I have an array of objects like so
obj = [
{
id: 3,
data: foo
},
{
id: 7,
data: bar
}
]
but I need to get it to
obj = {
3: {
id: 3,
data: foo
},
7: {
data: bar
}
}
having the id in the sub object is not needed but might be handy. What would be the best way to achieve this? I am not sure if there is a simple way to extract a property as an index?
Thanks for any help!
1 Answer