我有一个数组,如下:
var cString = [
['1','Techdirt','www.techdirt.com'],
['2','Slashdot','slashdot.org'],
['3','Wired','wired.com']
];
我想要将另一个数组以相同的格式添加到这个数组中:
var test = ['4','Stackoverflow','stackoverflow.com']
我尝试使用:
var newArray = $.merge(cString, test);
但是console.log(newArray);
输出:
[►Array,►Array,►Array,'4','Stackoverflow','stackoverflow.com']
所以我猜测我错过了一些显而易见的东西,或者正在尝试某些愚蠢的事情...有人能帮忙吗?
console.log(newArray)
现在返回4
= / - David Thomaslength
属性值应该是4
。 - user113716.push()
方法修改了原始数组,并返回新的长度。这就是为什么你的newArray
变量显示为4
的原因。 - user113716forDummies()
jsfiddle演示。这真的很有用 =) +1,并已接受! - David Thomas