Reputation:
I have a json array
var states = { "1": "California", "2": "LA" };
How can i count and print the items in states. It should print 2.
if I use states.length it gives an error
Upvotes: 1
Views: 153
Reputation: 11498
If you need to count the members of an object you can do this:
for (val in states) {
alert(states[val]);
count++;
}
alert(count);
Upvotes: 2
Reputation: 190986
Thats not an array.
var states = [ "California", "LA" ];
Upvotes: 1