This question already has an answer here:
(这个问题在这里已有答案:)
Is there any built-in function that can return the length of an object?
(是否有任何可以返回对象长度的内置函数?)
For example, I have a = { 'a':1,'b':2,'c':3 }
which should return 3
.
(例如,我有a = { 'a':1,'b':2,'c':3 }
应返回3
。)
If I use a.length
it returns undefined
.(如果我使用a.length
则返回undefined
。)
It could be a simple loop function, but I'd like to know if there's a built-in function?
(它可能是一个简单的循环函数,但我想知道是否有内置函数?)
There is a related question ( Length of a JSON object ) - in the chosen answer the user advises to transform object into an array, which is not pretty comfortable for my task.
(有一个相关的问题( JSON对象的长度 ) - 在选择的答案中,用户建议将对象转换为数组,这对我的任务来说不太舒服。)
ask by Larry Cinnabar translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…