I want to get below result in the end.
[{x: '10', y: '5'}, {x: '8', y: '4'}]
I don't understand why the result get by the following code is
[{x: '8', y: '4'}, {x: '8', y: '4'}]
var test =[["10", "5"],["8","4"]];
var series = {};
var sample = [];
for (var i = 0 ; i < test.length ; i++){
series.x = test[i][0];
series.y = test[i][1];
console.log(i);
console.log(series);
sample.push(series);
};
console.log(sample);
Can you give me some advice on what I lack?
let series = { x: test[i][0], y: test[i][1] };let sample = test.map(a => ({ x:a[0], y:a[1] }));let sample = test.map(([x,y])) => ({ x, y }));