我有一个像这样的数组:
错误 = [ {...}, {...}, {...} ]
它是一个instanceof
数组,但它只为.length
返回1?
相关代码:
if(data.error){
errors.push({'element':ele,error:data.error});
}
//Above is looped a few times and there are N number of errors now inside
console.log(errors) //Returns 2+ objects like {...}, {...}
console.log(errors.length) //Returns 1
对于 Uzi 和 Muirbot,这是错误数组:
[
Object
element: b.fn.b.init[1]
error: "You must enter "example" into the field to pass"
__proto__: Object
,
Object
element: b.fn.b.init[1]
error: "Crap!"
__proto__: Object
最佳答案
这是正确的,这段代码:
var errors = new Array();
errors.push({'element':'ele', error:'data.error'});
...将一个对象添加到数组中。该对象有两个属性。
关于javascript - 包含对象的数组长度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8719720/