Skip to content

Instantly share code, notes, and snippets.

@robertdempsey
Last active April 7, 2020 11:30
Show Gist options
  • Save robertdempsey/b5dc70e3d89606d1aa44ed1b36c040d4 to your computer and use it in GitHub Desktop.
Save robertdempsey/b5dc70e3d89606d1aa44ed1b36c040d4 to your computer and use it in GitHub Desktop.
Uses 'pick' to explicitly select the properties we want to keep, as opposed to throwing away the ones we don't.
const objectFromFrontend = {
_id: 5,
data: {
some: 1,
useful: 2,
data: 3
}
}
const objectToInsertIntoDB = _.pick(objectFromFrontend, ['data.useful', 'data.data']);
console.log(objectToInsertIntoDB)
/**
* {
* data: {
* useful: 2,
* data: 3
* }
* }
*/
console.log(objectFromFrontend)
/**
* {
* _id: 5,
* data: {
* some: 1,
* useful: 2,
* data: 3
* }
* }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment