Created
June 24, 2019 12:28
-
-
Save khaledosman/a619aa59bb9d791176db55f998430158 to your computer and use it in GitHub Desktop.
Function to filter an object and return specific keys only
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 _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