Last active
July 17, 2023 08:38
-
-
Save codeallday31/69e94b6e2a931ae60dcb55a6dc46a88c to your computer and use it in GitHub Desktop.
return only the selected keys in object
This file contains 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
const getData = (selectColumns = []) => { | |
let subset = object2 | |
if (columnsOnly.length !== 0) { | |
subset = object2.map(obj => | |
Object.fromEntries( | |
columnsOnly | |
.filter(key => key in obj) | |
.map(key => [key, obj[key]]) | |
) | |
) | |
} | |
return subset | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment