Skip to content

Instantly share code, notes, and snippets.

@bmarshall511
Created January 6, 2022 15:42
Show Gist options
  • Save bmarshall511/cdcb823e00c43284294b9a078bacc65f to your computer and use it in GitHub Desktop.
Save bmarshall511/cdcb823e00c43284294b9a078bacc65f to your computer and use it in GitHub Desktop.
Finds the index of a JS array that equals the array key value.
const items = {
[
id: 1,
name: 'Ben'
],
[
id: 2,
name: 'Angel'
],
[
id: 3,
name: 'Robin'
]
}
// Find the index of name = 'Angel'.
const index = items.findIndex(function(item) {
return item.name === 'Angel'
})
// Returns: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment