Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Destructure Restructure Pick
// given this object:
var origObj = {
first_name: 'test',
last_name: 'user',
email_address: 'user@test.com',
otherThing: 1234,
oneOtherThing: 5678
};
// what's the best/coolest way to get:
var user = {
first_name: 'test',
last_name: 'user',
email: 'user@test.com'
};
// Ramda pick can get an object with the specific props
var user = R.pick(['first_name', 'last_name', 'email_address'], origObj);
// Object destructuring can rename the email_address prop to 'email'
var { first_name, last_name, email: email_address } = origObj;
// How do I get both? Is the best/simplest way just boring ol':
var user = {
first_name: origObj.first_name,
last_name: origObj.last_name,
email: origObj.email_address
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.