Get the index of the first matching element:
let users = [
{ id: 1, name: "Alice" },
{ id: 2, name: "Bob" }
]
let index = users.findIndex(u => u.id === 2)
console.log(index) // 1
let notFound = users.findIndex(u => u.id === 99)
console.log(notFound) // -1
findIndex() returns -1 when no match is found, just like indexOf().