Lets say I have the following array of objects:
myArray = [
{name: 'First', parent: 1, delta: 2},
{name: 'Second', parent: 1, delta: 1},
{name: 'Third', parent: 2, delta: 1}
];
I would like to convert this array to an object, with keys for the parent, and values of the objects. e.g.:
result = {
1: [
{name: 'First', parent: 1, delta: 2},
{name: 'Second', parent: 1, delta: 1}
],
2: [
{name: 'Third', parent: 2, delta: 1}
]
}
I can do this using a forEach, or nested loops, but am wondering if there is a way using ES6 syntax to do this a bit more concise/inline, which would allow me to do things like sort on delta, etc.