I'm working with an array of objects, looking like this
myArray = [
{
id: 3,
data: foo
},
{
id: 7,
data: bar
}
]
However, I would like to transform it into the following structure
transformedArray = {
3: {
id: 3,
data: foo
},
7: {
data: bar
}
}
The presence of 'id' in each sub-object is not crucial but could be helpful. Is there a straightforward method to convert a property into an index?
Any assistance on this matter would be greatly appreciated!