Pawan
Pawan

Reputation: 32321

How can i get the count of JSON keys present under the array?

I have a JSON as shown below

var result = [
    {
        "SurCharges": "50"
    },
    {
        "SurCharges": "50"
    },
    {
        "SurCharges": "50"
    }
]

As there are 3 elements present inside the result array

How can i get its length ??

I have tried it this way

But it isn't working

could anybody please help

alert(result[0].length);

Upvotes: 0

Views: 38

Answers (2)

Farshad
Farshad

Reputation: 1485

you can use .lenght

var numberOfElements = result.length;
alert (numberOfElements);

Upvotes: 1

Nagy Nick
Nagy Nick

Reputation: 755

try this:

alert(result.length);

Upvotes: 1

Related Questions