Skip to content

Instantly share code, notes, and snippets.

@AzrizHaziq
Created December 10, 2018 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AzrizHaziq/2dbdd985efeb7b1ed763082d4070fb04 to your computer and use it in GitHub Desktop.
Save AzrizHaziq/2dbdd985efeb7b1ed763082d4070fb04 to your computer and use it in GitHub Desktop.
Part 2 Javascript Tip and Tricks Object Rest Paramater
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