The type of elements in the array.
A new object with the elements grouped by the key returned by the setterPropertyName
function.
const pets = [
{ type: 'dog', name: 'Fido' },
{ type: 'dog', name: 'Chacalin' },
{ type: 'cat', name: 'Mr. Brown' },
{ type: 'cat', name: 'Night' },
]
console.log(PUtilsArray.groupBy(pets, pet => pet.type))
// {
// dog: [
// { type: 'dog', name: 'Fido' },
// { type: 'dog', name: 'Chacalin' },
// ],
// cat: [
// { type: 'cat', name: 'Mr. Brown' },
// { type: 'cat', name: 'Night' },
// ],
// }
Groups elements of an array based on a key provided by a callback function.