I'm having two set of data as below:
let loadedData = [
[
{
y: 12,
x: 'Tue Sep 14 2021 05:15:38 GMT-0700 (Pacific Daylight Time)'
},
{
x: 10,
y: 'Tue Sep 14 2021 05:15:38 GMT-0700 (Pacific Daylight Time)'
}
],
[
{
x: 32,
y: 'Tue Sep 14 2021 05:15:38 GMT-0700 (Pacific Daylight Time)'
}
]
];
and
let seriesData = [
{
name: 'Graph',
type: 'Column',
data: []
},
{
name: 'Graph',
type: 'line',
data: []
}
];
I want to add loadedData's values inserted into seriesData's data property. The expected result should be like this.
result = [
{
name: 'Graph',
type: 'Column',
data: [
{
y: 12,
x: 'Tue Sep 14 2021 05:15:38 GMT-0700 (Pacific Daylight Time)'
},
{
x: 10,
y: 'Tue Sep 14 2021 05:15:38 GMT-0700 (Pacific Daylight Time)'
}
],
},
{
name: 'Graph',
type: 'line',
data: [
{
x: 32,
y: 'Tue Sep 14 2021 05:15:38 GMT-0700 (Pacific Daylight Time)'
}
]
}
];
I looked around for solutions but I couldn't find one that suits my criteria. Here's what I tried.
let loadedData = [
[{
y: 12,
x: 'Tue Sep 14 2021 05:15:38 GMT-0700 (Pacific Daylight Time)'
},
{
x: 10,
y: 'Tue Sep 14 2021 05:15:38 GMT-0700 (Pacific Daylight Time)'
}
],
[{
x: 32,
y: 'Tue Sep 14 2021 05:15:38 GMT-0700 (Pacific Daylight Time)'
}]
];
let seriesData = [{
name: 'Graph',
type: 'Column',
data: [],
},
{
name: 'Graph',
type: 'line',
data: []
}
];
for (let i = 0; i < loadedData.length; i++) {
const series = this.widget.config["options"].map((type) => {
console.log(type.graphType);
let el = [];
this.loadedData.forEach(element => {
el.push(element);
});
return {
name: type.sensor.sensorType,
type: type.graphType,
data: el[i]
};
});
seriesData = series;
}
.map()in the loop? What is that re-invention of.map()(.forEach()+.push()) in that loop?Array.prototype.concat()loadedData.concat(seriesData)developer.mozilla.org/es/docs/Web/JavaScript/Reference/…seriesDataalready has the expected result...