Created
July 30, 2014 20:36
-
-
Save westc/739db11416ff3295238b to your computer and use it in GitHub Desktop.
Takes an array (or uses all but the first parameter as an array) of keys and returns a new object containing all of the values with the specified keys.
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
function getProps(obj, keys) { | |
var ret = {}; | |
keys = ret.toString.call(keys) == '[object Array]' | |
? keys | |
: [].slice.call(arguments, 1); | |
for (var key, i = keys.length; i--;) { | |
key = keys[i]; | |
ret[key] = obj[key]; | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment