Skip to content

Instantly share code, notes, and snippets.

@khaledosman
Created June 24, 2019 12:28
Show Gist options
  • Save khaledosman/a619aa59bb9d791176db55f998430158 to your computer and use it in GitHub Desktop.
Save khaledosman/a619aa59bb9d791176db55f998430158 to your computer and use it in GitHub Desktop.
Function to filter an object and return specific keys only
function _filterObjectByKeys (object, keys) {
console.log({ object, keys })
return Object.keys(object).reduce((accum, key) => {
if (keys.includes(key)) {
return { ...accum, [key]: object[key] }
} else {
return accum
}
}, {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment