push data from array to another array in type script or javascript

i am trying to push data from array to another array in specific form :

first array have this data :

array1 = 1,2,3,4,5,6,7,8 

length even

I want to take first 2 in array1 and push in array2.

data in array2 must be :

array2: [1,2],[3,4],[5,6],[7,8]

Answer

You can do like the following:

var array1 = [1, 2, 3, 4, 5, 6, 7, 8],
  array2 = [];
var i, j, temparray, chunk = 2;
for (i = 0, j = array1.length; i < j; i += chunk) {
  temparray = array1.slice(i, i + chunk);
  array2.push(temparray)
}

console.log(array2)