JS - 数组的交叉合并

js

var arr1 = new Array(3);
arr1[0] = "a";
arr1[1] = "b";
arr1[2] = "c";
arr1[3] = "d";
var arr2 = new Array(3);
arr2[0] = "x";
arr2[1] = "y";
arr2[2] = "z";
console.log(arr1);
console.log(arr2);
var length = arr1.length;
console.log(length);
var arr3 = new Array(3);
for(var j=0;j<length;j++){
    var a = 2*j;
    console.log(a);
    var b = 2*j+1;
    console.log(b);
    arr3[a]=arr1[j];
    arr3[b]=arr2[j];
}
console.log(arr3);
var str = arr3.join("");
console.log(str);
//axbyczd
返回文章列表 文章二维码 打赏
本页链接的二维码
打赏二维码
期待你的评论