Welcome to the 41st Easy JavaScript tutorial, part of EasyProgramming.net. Did you think we were done with loops? Not yet! I had to save one until we covered JSON and custom JavaScript objects. In this tutorial, we're going to go over the for...in loop in JavaScript.
The for...in loop allows you to loop through properties of an object and its values, like how you can look through an array using the forEach loop. You can target both the property name and the property value with the for...in loop. So let's go over the syntax:
for...in
loop:for(property in object){ //E.g. object - person = {name:"Nazmus"}; var x = property; //name of the property itself - name var y = object[property]; //value of the property - Nazmus }
To fork the fiddle and follow along: https://jsfiddle.net/easyjs/2cqn3hfq/
Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!