-1

I'm trying to add an new array to an existing array.

For example the existing array is

[[1,2,3], [4,5,6]]

And now I have a new array which is

[7,8,9]

How can I get

[[1,2,3],[4,5,6],[7,8,9]]

I tried to use the spread operator, but haven't figured it out.

Thanks

Han
  • 19
  • 4
  • 1
    Please add the code you've attempted to your question as a [mcve] even if it's wrong. `arr1.push(arr2)` is a simple solution. – Andy Jun 14 '22 at 16:05

1 Answers1

1

You can push it:

const arr = [[1,2,3], [4,5,6]];
const arr2 = [7,8,9];
arr.push(arr2);

Or use the spread operator:

let arr = [[1,2,3], [4,5,6]];
const arr2 = [7,8,9];
arr = [...arr, arr2];
User456
  • 1,216
  • 4
  • 15