how to do a "flat push" in javascript?

You could use the concat method:

var num1 = [1, 2, 3];  
var num2 = [4, 5, 6];  
var num3 = [7, 8, 9];  

// creates array [1, 2, 3, 4, 5, 6, 7, 8, 9]; num1, num2, num3 are unchanged  
var nums = num1.concat(num2, num3);

apply does what you want:

var target = [1,2];
var source = [3,4,5];

target.push.apply(target, source);

alert(target); // 1, 2, 3, 4, 5

MDC - apply

Calls a function with a given this value and arguments provided as an array.


You can simply use spread syntax:

var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];

arr1 = [...arr1, ...arr2];
    // [0, 1, 2, 3, 4, 5]

Alternatively:

var arr1 = ['a', 'b', 'c'];
var arr2 = [1, 2, 3, ...arr1];
        // [1, 2, 3, 'a', 'b', 'c']

Demo:

var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];

arr1 = [...arr1, ...arr2];
console.log(arr1);

The easier way to do this.

   var arr1 = [1,2,3] 
   var arr2 = [4,5,6] 
   arr1.push(...arr2) //arr1 now contains [1,2,3,4,5,6]