I am using the standard groupBy function, modified by returning [hash] instead of hash. This returns an array of objects.
How can I instead output an array of arrays?
Standard groupBy Function
function groupBy(array, property) {
var hash = {};
for (var i = 0; i < array.length; i++) {
if (!hash[array[i][property]]) hash[array[i][property]] = [];
hash[array[i][property]].push(array[i]);
}
return [hash];
}
Output
[{key1:[array]}, {key2:[array]}, {key3:[array]}]
Desired Output
[[array1], [array2], [array3]]
Ultimately, I would like to run a for each over the output of arrays to pass into another function.
For instance,
let group = groupItemBy(cart, 'id');
console.log(group.length); // should be greater than 1 for multiple indexes
[key2:is invalid JavaScript syntax. Either you want a plain object with named keys or an array. You cannot have some half-half.keyandarrayare separated by:which is not valid.