Finds the index of an object in an array that contains a specific key-value pair.
The array of objects to search through
The key to match in the objects
The value associated with the key to match
The index of the object that matches the key-value pair. Returns -1 if no match is found
-1
This function is part of the array utilities module.
2.0.0
const data = [ { id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Joe' }];const result_index = find_index(data, 'name', 'Jane');console.log(result_index); // 1 Copy
const data = [ { id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Joe' }];const result_index = find_index(data, 'name', 'Jane');console.log(result_index); // 1
Finds the index of an object in an array that contains a specific key-value pair.