获取angularjs中的对象长度未定义 [英] Get the object length in angularjs is undefined
本文介绍了获取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.
这篇关于获取angularjs中的对象长度未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文