Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 901 Bytes

findIndexBy.md

File metadata and controls

30 lines (21 loc) · 901 Bytes

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.

Arguments:

  • 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.

Usage:

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

See also