Skip to content

Instantly share code, notes, and snippets.

@jonathan-fielding
Created February 18, 2021 23:25
Show Gist options
  • Save jonathan-fielding/a60cff7fa70b0e5234a0f88093c80fac to your computer and use it in GitHub Desktop.
Save jonathan-fielding/a60cff7fa70b0e5234a0f88093c80fac to your computer and use it in GitHub Desktop.
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