Created
October 19, 2017 19:53
-
-
Save kmaida/c144bbbcaebdee594e21f18be7af6004 to your computer and use it in GitHub Desktop.
Find the index of a particular object in an array by key/value pair.
This file contains hidden or 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 indexOfObj = (array, key, value) => { | |
for (let i = 0; i < array.length; i++) { | |
if (array[i][key] === value) { | |
return i; | |
} | |
} | |
return -1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment