I have this array
[
[ [ 'id', 'name' ], [ '1', 'A' ] ],
[ [ 'id', 'name' ], [ '2', 'B' ] ],
[ [ 'id', 'name' ], [ '3', 'C' ] ]
]
and i want it to be array of object with the corresponding value
[{id: 1, name: 'A'}, {id:2, name: 'B'}, {id:3, name: 'C'}]
thank you
Using
Array#mapiterate over the array.For every subarray, it will have a list of
keysand a list ofvalues. UsingArray#reduce, you can iterate overkeysto compute an object with the help of the third parameter, the index, to get each corresponding value: