Go Back

JavaScript: Object Rest Property

Posted on 2018-10-23

A nice little tool to "split" objects into something new.

// it's me
const user = {
  id: 1,
  email: 'mario@mariobros.com',
  firstName: 'Mario',
  job: 'plumber',
}

// we want to get the user without its email (privacy!)
const { email, ...userWithoutEmail } = user

console.log(email) // mario@mariobros.com
console.log(userWithoutEmail) // ​​​​​{ id: 1, firstName: 'Mario', job: 'plumber' }​​​​​