-2

I am new to javascript(json) I want to process each json object,the example prototype is given below please help me to solve the problem,I need to console it each room number given in json sample below

how can I loop through the each item in json array so that I can get individual json element and console it on browser window

let data = [  
   { 
        "king" :[
                    {
                        "id" : 1,
                        "room_no" : 101,
                        "price" : 2000  
                    },
                    {
                        "id" : 2,
                        "room_no" : 102,
                        "price" : 3000  
                    },
                ] 
    }      
] 

sorry for my bad english

Programmer
  • 1,973
  • 1
  • 12
  • 20
denzil
  • 83
  • 1
  • 1
  • 4

1 Answers1

1

Is this what you are looking for?

let data = [{
  "king": [{
      "id": 1,
      "room_no": 101,
      "price": 2000
    },
    {
      "id": 2,
      "room_no": 102,
      "price": 3000
    },
  ]
}]

data[0].king.forEach(item => console.log(item.room_no));
Thomas
  • 174,939
  • 50
  • 355
  • 478
Shaurya Dhadwal
  • 309
  • 2
  • 8