Created
March 19, 2014 02:32
-
-
Save metaist/9634482 to your computer and use it in GitHub Desktop.
Add .filter to JavaScript objects.
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
// Based on: http://stackoverflow.com/a/5072145/12815 | |
Object.filter = function(obj, predicate) { | |
var result = {}, key; | |
for(key in obj) { | |
if (obj.hasOwnProperty(key) && predicate.call(obj, key, obj[key])) { | |
result[key] = obj[key]; | |
}//end if: key added to result | |
}//end for: iterated over the object | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment