We have seen how to use some new syntax to extract elements from an array. Not to be left out, there are also some new facilities for combining arrays. Helpfully, as we'll see, the use of the spread operator mirrors that of the rest operator.
In this recipe, we'll take a look at how to use the spread operator to combine arrays.
This recipe assumes that you already have a workspace that allows you to create and run ES modules in your browser. If you don't, refer to the first two chapters.
- Open your command-line application, and navigate to your workspace.
- Create a new folder named
10-08-combine-arrays-using-spread
. - Create a
main.js
file that defines a newclass
namedRocket
that takes a constructor argumentname
and assigns it to an instance property:
// main.js class Rocket { constructor(name) { this.name = name; } }
- Create a
main
function with multiple array rockets, divided by nationality, and a standalone...