You can use a simple for loop and a temp variable and push values on every second index to final output
var arr = [`A`,`C`,`C`,`D`,`C`,`B`] let op = [] let temp = [] for(let i = 0; i < arr.length; i++){ temp.push(arr[i]) if( i % 2 == 1 ){ op.push(temp) temp = [] } } if( temp.length > 0 ){ op.push(temp) } console.log(op)