How to use the loop

Published on: April 1, 2017

Welcome to the 41st Easy JavaScript tutorial, part of 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 loop in JavaScript. 

The 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 loop.  So let's go over the syntax:

Syntax of a 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:

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!