0

所以,我有这个带有属性的数组,我想得到它的长度。在这种情况下,数组长度应为 2,因为只有 2 个“项目”

 {"items":[{"value":"2","valor":0,"name":"Limpeza"},
 {"value":"6","valor":0,"name":"TECREMOVE"}]}

我已经尝试过exist.length,但它返回undefined。我怎样才能得到它的长度?

4

2 回答 2

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- 该数组的长度。

于 2013-07-03T10:23:10.193 回答
1

您有一个名称为2object的属性。itemsarray

尝试:

var data =  {"items":[{"value":"2","valor":0,"name":"Limpeza"},
 {"value":"6","valor":0,"name":"TECREMOVE"}]};

var len = data.items.length;
于 2013-07-03T10:24:49.720 回答