how can I combine this:
let array1 = [1, 2, 3];
let array2 = [4, 5, 6];
// and get this
let result = [1, 4, 2, 5, 3, 6];
how can I combine this:
let array1 = [1, 2, 3];
let array2 = [4, 5, 6];
// and get this
let result = [1, 4, 2, 5, 3, 6];
use this:
let array1 = [1, 2, 3];
let array2 = [4, 5, 6];
let result = [];
for (var i = 0; i < array1.length; i++) {
result.push(array1[i]);
result.push(array2[i]);
}
console.log(result);
or
let array1 = [1, 2, 3];
let array2 = [4, 5, 6];
let result = array1.reduce(function(arr, v, i) {
return arr.concat(v, array2[i]);
}, []);
console.log(result);