Categories
JavaScript Answers

How to extend an existing JavaScript array with another array, without creating a new array?

Spread the love

To extend an existing JavaScript array with another array, without creating a new array, we call the push method.

For instance, we write

const a = [1, 2];
const b = [3, 4, 5];
a.push(...b);

to call a.push with the items in b as arguments to append the items in b into a in the order they’re listed.

We use the spread operator to call push with the entries in b as arguments.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.