我有一個數組,甚至一些元素:如何刪除陣列括號,但保留報價
var peoples = [
["1", "Adam", "Jones"],
["2", "Michael", "Jordan"],
["3", "Frank", "Forman"],
["4", "John", "Bryant"],
["5", "James", "Johnson"],
["6", "Vincent", "Carter"],
["7", "George", "Williams"],
["8", "Brandon", "Clarkson"]
];
,我試圖通過以下方式合併成對排列:
["1", "Adam", "Jones", "2", "Michael", "Jordan"]
["3", "Frank", "Forman","4", "John", "Bryant"]
等
我有下面的代碼有問題:
for (var i = 0; i < peoples.length/2; i++) {
array1[i].push(array2[i].join(","))
}
這是產生這一結果:
["1","Adam","Jones","2,Michael,Jordan"]
,它應該是:
["1","Adam","Jones","2","Michael","Jordan"]
這裏是我的jsfiddle https://jsfiddle.net/danny3b/k5hza694/
您正在使用'Array.prototype.join'連接'2,Micheal,Jordan' ......您不需要它。 – Hitmands