Indexes an array.
The type of elements in the array.
Target array.
Function that returns the key of the index.
Optional
Transformation elements.
An object with the indexed elements of the original array.
const pets = [ { type: 'dog', name: 'Fido' }, { type: 'dog', name: 'Chacalin' }, { type: 'cat', name: 'Mr. Brown' }, { type: 'cat', name: 'Night' },]console.log(PUtilsArray.index(pets, pet => pet.type))// {// dog: { type: 'dog', name: 'Fido' },// cat: { type: 'cat', name: 'Mr. Brown' },// } Copy
const pets = [ { type: 'dog', name: 'Fido' }, { type: 'dog', name: 'Chacalin' }, { type: 'cat', name: 'Mr. Brown' }, { type: 'cat', name: 'Night' },]console.log(PUtilsArray.index(pets, pet => pet.type))// {// dog: { type: 'dog', name: 'Fido' },// cat: { type: 'cat', name: 'Mr. Brown' },// }
Indexes an array.