Skip to content

Instantly share code, notes, and snippets.

@FelipeJz
Last active August 5, 2016 17:44
Show Gist options
  • Save FelipeJz/e77285401215d6ac6bd7a497aa1a5e29 to your computer and use it in GitHub Desktop.
Save FelipeJz/e77285401215d6ac6bd7a497aa1a5e29 to your computer and use it in GitHub Desktop.
Get array index by the value of the object property
//array = [{object: 'property'}, {object2: 'property2'}]
var arrayIndexByPropertyValue = function (array, property, value){
//Runs the array
for(var i = 0, m = null; i < array.length; ++i) {
//Compares the property value
if(array[i][property] == value) {
//If correct returns it
return i;
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment