所以,我有这个带有属性的数组,我想得到它的长度。在这种情况下,数组长度应为 2,因为只有 2 个“项目”
{"items":[{"value":"2","valor":0,"name":"Limpeza"},
{"value":"6","valor":0,"name":"TECREMOVE"}]}
我已经尝试过exist.length
,但它返回undefined
。我怎样才能得到它的长度?
所以,我有这个带有属性的数组,我想得到它的长度。在这种情况下,数组长度应为 2,因为只有 2 个“项目”
{"items":[{"value":"2","valor":0,"name":"Limpeza"},
{"value":"6","valor":0,"name":"TECREMOVE"}]}
我已经尝试过exist.length
,但它返回undefined
。我怎样才能得到它的长度?
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
- 该数组的长度。
您有一个名称为2object
的属性。items
array
尝试:
var data = {"items":[{"value":"2","valor":0,"name":"Limpeza"},
{"value":"6","valor":0,"name":"TECREMOVE"}]};
var len = data.items.length;