Codementor Events

Understanding the Spread Operator

Published Jun 17, 2019
Understanding the Spread Operator

The object spread syntax was recently added to the JavaScript specification.

Here are some reasons why it has become popular so quickly:

The spread operator lets you fully copy or do a "deep copy" of enumerable properties from one object to another object without having to perform a clone or copy operation with sometimes a couple of lines of JavaScript Code.

It's simplest use can be explained with a simple copy operation:

var c = {a:{b:1}, c:{arr: [a, b, c]}];
let d = {...c};

The advantage of using the object spread syntax becomes more apparent the more complex the objects that you are working with becomes.

Discover and read more posts from Theresa Mostert
get started