Question

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 );
Was it helpful?

Solution

Use *.lenght

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

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

OTHER TIPS

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();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top