For…In Loops

Video

JavaScript Notes

JavaScript
    var monsters = {'Canada':'Sasquatch', 'Nepal':'Yeti', 'Scotland':'Loch Ness Monster'};
     
    console.log(monsters);
    var pets = ["Woody", "Roxy", "Bob"];
    
    // var in object
    for (property in monsters){ console.log(property); console.log(monsters[property]);
    console.log("In", prop, "we have the", monsters[property]);
    }
    
    // var in array
    for (index in pets){ console.log(index); console.log(pets[index]);
    console.log("In", index, "we have the", pets[index]);
    }