0

I have below JSON and I want to iterate it through javascript. How do I do it.

var data= {"key1":[{"alfa":"abcd","a":"a1","b":"b1","c":"c1","d":"d1"},
     {"number":"1234","1":"11","22":"2","3":"33","4":"44"}],

      "key2":[{"alfa":"abcd","a":"a1","b":"b1","c":"c1","d":"d1"},
     {"number":"1234","1":"11","2":"22","3":"33","4":"44"}]}

DS Used: Map of String,List of Object

Alex Kudryashev
  • 9,120
  • 3
  • 27
  • 36
Gopal
  • 1
  • 1

2 Answers2

1
Object.keys(data).forEach(key => {
  for(let item of data[key]){
    Object.keys(item).forEach(key => {
      console.log(item[key]) // do stuff here
    })
  }
})

I'd so something like this

Robbie Milejczak
  • 5,664
  • 3
  • 32
  • 65
0

Here are some examples how you can access the fields:

console.log(data.key1[0].alfa);
console.log(data.key2[0].alfa);
console.log(data.key2[0].a);
Janine Kroser
  • 444
  • 2
  • 6
  • 23