Skip to content

Instantly share code, notes, and snippets.

@westc
Created July 30, 2014 20:36
Show Gist options
  • Save westc/739db11416ff3295238b to your computer and use it in GitHub Desktop.
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.
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