I'm trying to find a javascript code that simultaneously enters data from two arrays and places them into one array. I thought this would work, but looking over it, it doesn't quite do the job.
var tempDeck = [];
var array1 = ["one", "two"];
var array2 = ["three", "four"];
for (i = 0; i < array1.length + array2.length; i++){
if (i % 2 == 0){
tempdeck.push(array1[i]);
}else{
tempdeck.push(array2[i]);
}
}
I need it to output the result of
tempdeck[0] = "one";
tempdeck[1] = "three";
tempdeck[2] = "two";
tempdeck[3] = "four";
I'm trying to avoid manually placing them in, because the number or arrays is based on user input. :( Any suggestions?