新手问题。我将3个对象推入数组:



var objarray = [{}];
objarray.push({"color":"red", "title":"ABC"});
objarray.push({"color":"blue", "title":"DEF"});
objarray.push({"color":"green", "title":"XYZ"});

console.log(objarray);





Firebug显示有4个元素。这仅在对象数组中发生吗?

jquery - Firebug显示Object Array还有1个元素-LMLPHP

最佳答案

创建带有空对象-[{}]的数组时,它将显示4个对象。删除内部括号,您将只有三个填充的对象:



var objarray = []; // note: removed {}
objarray.push({"color":"red", "title":"ABC"});
objarray.push({"color":"blue", "title":"DEF"});
objarray.push({"color":"green", "title":"XYZ"});

console.log(objarray);

关于jquery - Firebug显示Object Array还有1个元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47018936/

10-09 01:35