Skip to content

Instantly share code, notes, and snippets.

@westc
Created July 30, 2014 20:34
Show Gist options
  • Save westc/d9b8c3254db8d21ceeda to your computer and use it in GitHub Desktop.
Save westc/d9b8c3254db8d21ceeda to your computer and use it in GitHub Desktop.
Takes an array (or uses all but the first parameter as an array) of strings, removes those properties from the given object and returns an object of all of the removed values.
function popProps(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];
delete obj[key];
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment