Skip to content

Instantly share code, notes, and snippets.

@codeallday31
Last active July 17, 2023 08:38
Show Gist options
  • Save codeallday31/69e94b6e2a931ae60dcb55a6dc46a88c to your computer and use it in GitHub Desktop.
Save codeallday31/69e94b6e2a931ae60dcb55a6dc46a88c to your computer and use it in GitHub Desktop.
return only the selected keys in object
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