Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Length Of Json object

Tags:

json

jquery

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

like image 483
droidev Avatar asked Mar 22 '14 16:03

droidev


People also ask

How do I find the length of a JSON object?

To get length of json object in javascript, just use Object. keys() method with length property. it will return length of object.

What is the size of a JSON object?

The maximum length of a JSON type using a binary storage format is 16776192 bytes.

How do you find the number of elements in a JSON array?

Description. JsonArray::size() gets the number of elements in the array pointed by the JsonArray . If the JsonArray is null, this function returns 0 .


1 Answers

I have got the answer

Object.keys(result).length // returns 5

UPDATE

From the comment this does not work on IE 7 and 8

like image 60
droidev Avatar answered Sep 27 '22 20:09

droidev