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.
id
: The id of object to be searched.entityArray
: The array of objects in which the given id will be searched.
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