I have a nested array like this
array = [[1, 698],[32, 798],[69, 830],[95, 500]]
I want to have a function that return the result in this format
[
{
id: 1,
score: 698
},
{
id: 32,
score: 798
},
{
id: 69,
score:830
},
..... the rest of the array
]
I did use a for loop but with no success, and I have no idea on how to aproach the situation.
for(var i = 0; i <= array.lenght ; i++){
var obj={}
var res = []
res.push(array[i])
}
You can take the advantage of the power of the ES6 syntax:
var array = [
[1, 698],
[32, 798],
[69, 830],
[95, 500],
];
var res = array.map(([id, score]) => ({id, score}));
console.log(res);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With