[Vuejs]-How to assign a number of properties to an existing object IF that property also has nested properties inside of it?

0👍

Here’s one method of building that object using the spread syntax:

// Empty chartData
const chartData = {};

// Your two sets of data
const labels = ['One', 'Two'];
const datasets = { datasets: [{ data: ['5', '10'], label: 'Chart'}] };

// Merge the existing chartData, and labels and datasets together
const newChartData = { chartData: { ...chartData, labels: [...labels], ...datasets } };

console.log(newChartData);

Leave a comment