Iterating JavaScript Objects

Use a for in loop to iterate over an objects properties and values. The var which is set to key in this example could be any word you choose. To get the value use bracket notation, that way you can pass in the key variable on each iteration of the loop.

var box = {};
						
box['material'] = "cardboard";						
box[0] = 'meow';
box['^&*'] = "testing 123";

for(var key in box) {
  console.log(key);
  console.log(box[key]); // use bracket notation to access the key variable
}