The Map groupBy() static method groups the elements of a given iterable using the values returned by a provided callback function. The final returned Map uses the unique values from the test function as keys, which can be used to get the array of element in each group.

    
    const inventory = [
      { name: 'asparagus', type: 'vegetables', quantity: 9 },
      { name: 'bananas', type: 'fruit', quantity: 5 },
      { name: 'goat', type: 'meat', quantity: 23 },
      { name: 'cherries', type: 'fruit', quantity: 12 },
      { name: 'fish', type: 'meat', quantity: 22 },
    ];

    const inventoryGrouped = Map.groupBy(inventory, type =>
      inventory.type
    );

    console.log(inventoryGrouped);

    console.log(inventoryGrouped.get(meat));
    // [{ name: "bananas", type: "fruit", quantity: 5 }]