Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 769 Bytes

findIndexById.md

File metadata and controls

29 lines (20 loc) · 769 Bytes

findIndexById (source code)

  • Curried: true
  • Failsafe status: alternative available

The findIndexById function is used to find the index of an item within an array of items based on the id property of the entities within it.

Arguments:

  • id: The id of object to be searched.
  • entityArray: The array of objects in which the given id will be searched.

Usage:

const array = [
  { id: "1001", name: "Sam" },
  { id: "2001", name: "Oliver" },
];

findIndexById("2001", array); // returns 1
findIndexById("1001", array); // returns 0
findIndexById("3001", array); // returns -1

See also