Last active
April 7, 2020 11:30
-
-
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.
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 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