1

给定这样的数据:

var json = [ 
  { "id": "A", "status":   1, "rank": 30,  "score": 0.1  },
  { "id": "B", "status":   1, "rank": 30,  "score": 0.7  },
  { "id": "C", "status":   1, "rank": 60,  "score": 0.8  },
  { "id": "AB", "status":  1, "rank": 160, "score": 0.6  },
  { "id": "ABC", "status": 1, "rank": 400, "score": 0.2 }
];

如何获取 id 的长度?

小提琴:http: //jsfiddle.net/RBSC9/


以下不起作用:

var l = (json[3].id).text().length();
console.log("l = "+ l );
4

3 回答 3

1

Use *.lenght

var l = json[3].id.length;
console.log("length["+json[3].id+"] = "+ l );

http://jsfiddle.net/RBSC9/2/

于 2013-07-05T11:33:13.543 回答
1
var len = json[3].id.length;
console.log("len = "+ len);
于 2013-07-05T11:35:36.107 回答
1

请参考更新小提琴链接http://jsfiddle.net/RBSC9/3/

var l = (json[3].id).length

你想提lengthlength;length();

于 2013-07-05T11:35:48.413 回答