Created
December 15, 2014 22:00
-
-
Save maxkrieger/73492e9aa237a224052a to your computer and use it in GitHub Desktop.
associative arrays made easy.
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
/* | |
findBy: associative arrays made easy. | |
Usage: | |
var myArr = [{id: "foo"}, {id: "bar"}]; | |
var result = findBy(myArr, "id", "foo"); //returns {id: "foo"} | |
*/ | |
var findBy = function(arr, identifier, name) { | |
for (var i = 0; i < arr.length; i++) { | |
if (arr[i][identifier] == name) { | |
return arr[i]; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment