我们说我有一个这样的数组:
var myArray = [
['a', 'b'],
['c', 'd']
]
如何连接这个二维数组,以便得到这个结果:
['ab', 'cd']
答案 0 :(得分:5)
var newArray = myArray.map(function (item) {return item.join('');}); //["ab", "cd"]
答案 1 :(得分:0)
http://jsfiddle.net/6bw65xj4/1/
var tmp = '',
newArray = [],
myArray = [
['a', 'b'],
['c', 'd']
];
for(var i=0; i<myArray.length; i++){
for(var j=0; j<myArray[i].length; j++) {
tmp = tmp + myArray[i][j];
}
newArray.push(tmp);
tmp = ''
}
console.log(newArray);