From the course: Learning ECMAScript 6+ (ES6+)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using the array spread operator

Using the array spread operator - JavaScript Tutorial

From the course: Learning ECMAScript 6+ (ES6+)

Start my 1-month free trial

Using the array spread operator

- [Instructor] The spread operator does a lot of powerful things with three small dots. The spread operator turns the elements of an array into arguments of a function call or into elements of an array literal. Let's take a look at this. I'm going to create an array of strings. So we have some cats here. And then I'll create another array of dogs. Then I'm going to create an array of animals. Smoky. We have Miro the fish, and then we have Swimmy, a shark. So if I wanted to add the cats and dogs to our animals list, I might want to just add them here. So I'll just comma-separate them, and then I'll console.log the animals to see what we get. But then immediately, we notice that we have our three items from the original array, but then we have two nested arrays in here, which is really not what I was going for. I want everything to be at the same level with no nesting. Here's where the spread operator comes into play. I…

Contents