Created
February 18, 2021 23:25
-
-
Save jonathan-fielding/a60cff7fa70b0e5234a0f88093c80fac to your computer and use it in GitHub Desktop.
This file contains hidden or 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, props) { | |
return props.reduce(function(result, prop) { | |
result[prop] = obj[prop]; | |
return result; | |
}, {}); | |
} | |
const person = { | |
name: 'Jonathan', | |
age: 21, | |
gender: 'male' | |
} | |
const picked = pick(person, ['name', 'age']); | |
console.log(picked); // Result { name: 'Jonathan', age: 21 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment