Skip to content

Instantly share code, notes, and snippets.

@PandaWhisperer
Created June 1, 2015 21:45
Show Gist options
  • Save PandaWhisperer/5bbeb1cf817eb6716bc3 to your computer and use it in GitHub Desktop.
Save PandaWhisperer/5bbeb1cf817eb6716bc3 to your computer and use it in GitHub Desktop.
function pick(obj, ...keys) {
if (typeof obj !== 'object') return;
var result = {};
for (var key of Object.keys(obj)) {
if (keys.indexOf(key) >= 0) result[key] = obj[key];
}
return result;
}
var obj = { one: 1, two: 2, three: 3 }
console.log(pick(obj, ['one', 'two']));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment