I have this array:
const array = [
{id: 'firstId'},
{id: 'SecondId'},
{id: 'ThirdId'}
]
I want to reach this result:
array = [
{firstId: null},
{SecondId: null},
{ThirdId: null}
]
so I tried:
array.map([key,value] => {key:value});
but I got an array of undefined
>Solution :
One way could be to do something like:
const array = [
{id: 'firstId'},
{id: 'SecondId'},
{id: 'ThirdId'}
];
const res = array.map( (obj) => ({ [obj.id]: null }) );
console.log(res);
Note the parentheses around the arrow function arguments and the parentheses around the curly braces to indicate that the curly braces do not form a block for the function body.