3

I have an json Object like this.

{'01/19/2012': Array[1],'02/19/2012': Array[7],'03/19/2012': Array[6]}

Now i want to iterate this map

I need result like

Date : 01/19/2012
      Array Data here

Date : 02/19/2012
      Array Data here

Thanks!!

Naveen A
  • 533
  • 4
  • 8
  • 16

2 Answers2

12

Use a for loop in which you use condition: "var x in y" where y is the object.

for (var key in p) {
  if (p.hasOwnProperty(key)) {
    alert(key + " -> " + p[key]);
  }
}

https://stackoverflow.com/a/684692/680578

Community
  • 1
  • 1
Kristian
  • 21,204
  • 19
  • 101
  • 176
-1

Use a "for ... in" loop.

http://www.w3schools.com/js/js_loop_for_in.asp

If you need to sort the data (as you might with dates), use "for ... in" to push the elements into an Array, use sort(), and then process the results.

More on sort(): http://www.w3schools.com/jsref/jsref_sort.asp

Ross Smith
  • 747
  • 4
  • 5