To find index of an object by key and value in a JavaScript array, we use the findIndex
method.
For instance, we write
const index = peoples.findIndex((p) => p.attr1 == "john");
to call peoples.findIndex
with a callback that checks if attr1
property of each object in peoples
is 'john'
.
The first index of the found item is returned.