I have a JSON data which look like this:
{
"chart":[
[
1627776011000,
28
],
[
1627776371000,
38
],
[
1627776731000,
48
],
...
]
}
I want to use this data in Chart.js where 1627776011000 ... are x axis values and 28 ... are y axis values.
I know I can do it with an array push
const myArr = JSON.parse(dataJSON);
const data = [];
const labels = [];
myArr.chart.forEach((item) => {
labels.push(item[0]);
data.push(item[1]);
});
but could there be a better way, for example with a map?
reduce, but the way you do it is just fine. Try not to look for the "perfect" solution, it is much more practical to settle with a working solution.