Using forEach () with your code example (the room is an object), you would look at this:
temp1.rooms.forEach(function(element) { console.log(element) });
Using For with your code example (if we want to return the rooms) looks like this:
for(let val of rooms.room) { console.log(val.room); }
Note: the noticeable difference between For for and forEach is For of break break and forEach does not have the ability to break to stop the loop (without throwing an error).
source share