tags:

views:

51

answers:

2

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

+1  A: 

Thats not an array.

var states = [ "California", "LA" ];
Daniel A. White
Thats[sic] not an answer.
Aviral Dasgupta
+2  A: 
Alex Ciminian
If you also want to print the states, you can add a line after "count++" to print the state name.
Eddie Welker
I edited the code. Thanks :).
Alex Ciminian