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.