array.length的结果未定义,但在控制台中有元素

时间:2017-07-17 11:53:10

标签: javascript angularjs arrays

我有一个对象:

0.27.5

还有一些包含元素var Points={ cost:[], amount:[], risk:[] }; 的数组。 然后我推送这个数组中的元素:

ar=[several elements]

但是,当我试图获得长度时,for(var i=0;i<ar.length;i++){ if() Points.amount.push(some_element); else if() Points.cost.push(some_element); else if() Points.risk.push(some_element); } 我得到console.log(Points.cost.length)。此外,当我0的结果为:enter image description here

阵列(0)??? 但是如果我在控制台中打开这个对象,我会看到enter image description here

console.log(Points)的结果为console.log(Points.cost[0])。为什么会这样??

P.S。使用Angularjs,但我认为这不重要,对我的问题有任何影响。

0 个答案:

没有答案