Search⌘ K

Object Destructuring: The Role of the Spread Operator

Explore how to use the spread operator in object destructuring to create copies of JavaScript objects while adding or updating properties. This lesson helps you write extensible, maintainable code by avoiding common pitfalls in object copying, especially in contexts like Redux where immutability is key.

Extracting with ...

In the previous lessons on object destructuring examples, we have extracted part of the object, leaving behind some properties. Sometimes, we want to copy the whole object, and at the same time, maybe add new properties or change the values of existing properties. Destructuring can do this quite well.

Using destructuring to copy object properties

For example, the popular JavaScript state container library Redux is based on the immutable state. Instead of modifying existing objects, it transforms them into new objects. Typically, a transformation may change one or two property ...