Created
June 1, 2015 21:45
-
-
Save PandaWhisperer/5bbeb1cf817eb6716bc3 to your computer and use it in GitHub Desktop.
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 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