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);
Source:stackexchange.com