findIndexBy (source code)
- Curried: true
- Failsafe status: alternative available
The findIndexBy
function finds the index of the item in the array that matches
the provided pattern.
pattern
: The pattern using which an object will be matched.entityArray
: The array of objects in which the object with the given pattern will be searched.
const array = [
{ id: 1, name: "Sam", address: { street: "First street", pin: 123456 } },
{ id: 2, name: "Oliver", address: { street: "Second street", pin: 654321 } },
];
findIndexBy({ name: "Sam" }, array); // returns 0
findIndexBy({ id: 2, address: { pin: 654321 } }, array); // returns 1
findIndexBy({ id: 3 }, array); // returns -1