所以,我有这个属性的数组,我想得到它的'长度。在这种情况下,数组长度应为2,因为只有2个“项”
{"items":[{"value":"2","valor":0,"name":"Limpeza"},
{"value":"6","valor":0,"name":"TECREMOVE"}]}
我已经尝试exist.length
,但它会返回undefined
。我怎样才能得到它的长度?
答案 0 :(得分:2)
var myObj = {"items":[{"value":"2","valor":0,"name":"Limpeza"},
{"value":"6","valor":0,"name":"TECREMOVE"}]};
var arrLength = myObj.items.length;
myObj.items
- 是数组myObj.items.length
- 该数组的长度。
答案 1 :(得分:1)
您有 object
,其中一个名称为 items
的属性为array
,其长度为var data = {"items":[{"value":"2","valor":0,"name":"Limpeza"},
{"value":"6","valor":0,"name":"TECREMOVE"}]};
var len = data.items.length;
2。
尝试:
{{1}}