Created
December 10, 2018 08:51
-
-
Save AzrizHaziq/2dbdd985efeb7b1ed763082d4070fb04 to your computer and use it in GitHub Desktop.
Part 2 Javascript Tip and Tricks Object Rest Paramater
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
var greetUsers = users.map(user => { | |
const { name, ...payload } = user // we collect all others key into payload | |
return { | |
id: payload.id, | |
name: `Hello ${name}`, | |
email: payload.email, | |
phone: payload.phone, | |
website: payload.website, | |
company: payload.company, | |
address: payload.id, | |
} | |
}) | |
// 👍 more shorter syntax | |
var greetUsers = users.map(({ name, ...payload }) => ({ | |
id: payload.id, | |
name: `Hello ${name}`, | |
email: payload.email, | |
phone: payload.phone, | |
website: payload.website, | |
company: payload.company, | |
address: payload.id, | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment