I am looking to create a new array where objects are grouped based on a common key value pair.
For instance, starting with an Ungrouped Array:
let ugArray = [
{name: 'jack', type: 'dog'},
{name: 'brad', type: 'dog'},
{name: 'ella', type: 'cat'},
{name: 'lily', type: 'cat'},
{name: 'rod', type: 'goat'},
]
The goal is to group the objects by their 'type' property resulting in the following output:
let groupedArray = [
{dog: [
{name: 'jack', type: 'dog'},
{name: 'brad', type: 'dog'}
]},
{cat: [
{name: 'ella', type: 'cat'},
{name: 'lily', type: 'cat'},
]},
{goat: [
{name: 'rod', type: 'goat'}
]}
]