For…Of Loops
Video
JavaScript Notes
JavaScript
// for…of loops
// for…of vs for…in loops
let supernatural = {
"actors":['Jared Padelecki', 'Jensen Ackles', 'Mark Sheppard', 'Misha Collins'], "characters":['Sam Winchester', 'Crowley', 'Castriel'], "seasons":12};
for(prop in supernatural){ // supernatural is an object
console.log(prop, typeof supernatural[prop], Array.isArray(supernatural[prop])); // prop represents the properties of the object
}
for(index in supernatural.actors){ // supernatural.actors is an array
console.log(index, supernatural.actors[index]); // index represents the indices of the array
}
for(name of supernatural.actors){
console.log(name); // name represents the values of the array
}
Feedback
Submit and view feedback