I've got an array of objects containing IDs (non unique)
[ { a: 1 }, { a: 1 }, { a: 2 }, { a: 1 }, { a: 1 }, { a: 1 } ]
I'm trying to group objects by their keys, for example:
[ [{ a: 1 }, { a: 1 }], [{ a: 2 }], [{ a: 1 }, { a: 1 }, { a: 1 }] ]
Initially I thought to iterate over each object, recursively checking all previous keys - but as the list is going to contain hundreds of objects, that would be inefficient.
Is there an inbuilt lodash method that would be suitable for this? or else what would be the best approach
forloops are the most efficient iterators in JS. You will need to iterate these. You might consider using a generator function that yields each of the objects in the original array to handle them individually. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…*