Search⌘ K
AI Features

Destructuring with the Spread Operator

Explore how to use the spread operator in array destructuring in JavaScript ES6. Understand capturing remaining elements in arrays, simplifying code and avoiding ambiguity through clear placement rules of the rest parameter. This lesson enhances practical coding skills with modern JavaScript syntax.

We'll cover the following...

Let’s create an array that contains the last four characters of another array:

Node.js
let notgood = 'not good'.split( '' );
let [ ,,,, ...good ] = notgood;
console.log( good );
// ["g", "o", "o", "d"]

The string not good is split into ...