I have json object which is returned from php file, the json values are as follows
{
"0": {
"id": "35",
"name": "first name",
"date": "2014-03-03",
"age": "25"
},
"1": {
"id": "36",
"name": "name",
"date": "0000-00-00",
"age": "25"
},
"2": {
"id": "37",
"name": "myname",
"date": "0000-00-00",
"age": "25"
},
"average_age": 25,
"count": 3
}
How do I get the count of values other than average_age and count that is for the given json object i want to get 3 as length in jQuery
To get length of json object in javascript, just use Object. keys() method with length property. it will return length of object.
The maximum length of a JSON type using a binary storage format is 16776192 bytes.
Description. JsonArray::size() gets the number of elements in the array pointed by the JsonArray . If the JsonArray is null, this function returns 0 .
I have got the answer
Object.keys(result).length // returns 5
UPDATE
From the comment this does not work on IE 7 and 8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With