Last active
August 5, 2016 17:44
-
-
Save FelipeJz/e77285401215d6ac6bd7a497aa1a5e29 to your computer and use it in GitHub Desktop.
Get array index by the value of the object property
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
//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