I have a collection of objects:
arr1 = [{catid: 1, name: 'mango', category: 'fruit'}, {catid: 2, name: 'potato', category: 'veg'}, {catid: 3, name: 'chiken', category: 'nonveg'},{catid: 1, name: 'apple', category: 'fruit'}, {catid: 1, name: 'banana', category: 'fruit'}];
I am looking to transform the array into a two-dimensional array based on the catid property (essentially grouping elements with the same catid together):
arr2 = [[{catid: 1, name: 'mango', category: 'fruit'},{catid: 1, name: 'apple', category: 'fruit'}, {catid: 1, name: 'banana', category: 'fruit'} ],[{catid: 2, name: 'potato', category: 'veg'}],[{catid: 3, name: 'chicken', category: 'nonveg'}]]
How can I achieve this in typescript or javascript?