So, I have an array as follows.
Array.from(Array(3).keys())
//=> [0, 1, 2]
I wanted to convert this array to object and assign a static key called value to each elements.
So the final result should be
result = [
{
value: 0,
},
{
value: 1,
},
{
value: 2,
}
]
>Solution :
Just map it:
const source = Array.from(Array(3).keys());
const result = source.map(x => ({value: x}));
console.log(result);