Created
September 13, 2011 14:13
-
-
Save davidwood/1213888 to your computer and use it in GitHub Desktop.
Find an object in an array by id property
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
var myId = 10; | |
var index; | |
var item = _.detect(this._list, function(val, indx) { | |
if (val.id == myId) { | |
index = indx; | |
return true; | |
} | |
}, this); | |
if (index) { | |
console.log('Matching index is: ' + index); | |
console.log('Matching item is : ' + item); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment