I have an array like this:
[
{
0 : {
id: 'somevalue',
name: 'John Doe',
age: '20'
}
}
...
]
I would like to modify the array, for example to set the key to the id attribute like this:
[
{
somevalue : {
name: 'John Doe',
age: '20'
}
}
]
What would be the best way to achieve this. Thanks for your time.
data.map(function(d) { let ref = d[0]; let id = ref.id; delete ref.id; return { [id]: ref }; })