获取angularjs中的对象长度未定义
问题描述:
如何获取物体长度?
在控制台中,我的对象如下所示:
In console my object looks like this:
Object {
2: true,
3: true,
4: true
}
.length
将给我未定义.我只想获取这种情况下的results = 3
.
.length
will give me undefined. I just want to get the results = 3
for this case.
答
var keys = Object.keys(objInstance);
var len = keys.length;
len是您的长度".
Where len is your "length."
在某些情况下,我可能还没有想到这是行不通的,但是在给定示例的情况下,它应该可以满足您的需要.
There may be circumstances I haven't thought of where this doesn't work, but it should do what you need, given your example.