문제

Given data such :

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 }
];

How to get the id's length ?

Fiddle: http://jsfiddle.net/RBSC9/


The following doesn't works:

var l = (json[3].id).text().length();
console.log("l = "+ l );
도움이 되었습니까?

해결책

Use *.lenght

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

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

다른 팁

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

Please refer the update fiddle link http://jsfiddle.net/RBSC9/3/

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

You want to mention length like length; not length();

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top