Skip to content

Instantly share code, notes, and snippets.

@kmaida
Created October 19, 2017 19:53
Show Gist options
  • Save kmaida/c144bbbcaebdee594e21f18be7af6004 to your computer and use it in GitHub Desktop.
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.
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