Created
January 6, 2022 15:42
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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