Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Sapphiron532/6586db27b6b9e3e85de61e874876a7d3 to your computer and use it in GitHub Desktop.
Save Sapphiron532/6586db27b6b9e3e85de61e874876a7d3 to your computer and use it in GitHub Desktop.
ES5/ES6/ES2017 omit & pick
Object.keys(obj)
.filter((key) => ['blacklisted', 'keys'].indexOf(key) < 0)
.reduce((newObj, key) => Object.assign(newObj, { [key]: obj[key] }), {})
Object.entries(obj)
.filter(([key]) => !['blacklisted', 'keys'].includes(key))
.reduce((obj, [key, val]) => Object.assign(obj, { [key]: val }), {});
Object.keys(obj)
.filter((key) => ['whitelisted', 'keys'].indexOf(key) >= 0)
.reduce((newObj, key) => Object.assign(newObj, { [key]: obj[key] }), {})
Object.entries(obj)
.filter(([key]) => ['whitelisted', 'keys'].includes(key))
.reduce((obj, [key, val]) => Object.assign(obj, { [key]: val }), {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment