I have an first array and the second array with elements I want to add to the first array
arr1 = [ 1, 2, 3 ];
arr2 = [ 4, 5, 6 ];
arr1.push(arr2); // [ 1, 2, 3, [ 4, 5, 6]] but i need [ 1, 2, 3, 4, 5, 6 ]
How can I do it?
I have an first array and the second array with elements I want to add to the first array
arr1 = [ 1, 2, 3 ];
arr2 = [ 4, 5, 6 ];
arr1.push(arr2); // [ 1, 2, 3, [ 4, 5, 6]] but i need [ 1, 2, 3, 4, 5, 6 ]
How can I do it?
Either, modify the array and use .concat
:
arr1 = arr1.concat(arr2)
Or, push with the spread operator:
arr1.push(...arr2)
You can do it with spread operator:
arr1 = [...arr1, ...arr2];