本文介绍了压缩两个数组的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javascript中有两个数组:

I have two arrays in javascript:

var array1 = ["a","b","c"];
var array2 = ["e","f","g"];

我希望结果数组如下所示:

And I want the resulting array to be like this:

array3 = ["a","e","b","f","c","g"];

有什么办法吗?

推荐答案

会直接循环吗?

array3 = new Array();

for(var i = 0; i < array1.length; i++)
{
    array3.push(array1[i]);
    array3.push(array2[i]);
}

这篇关于压缩两个数组的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 13:21
查看更多