for-in loops

The for-in loop is specifically designed to work with objects. Learn how to loop through an object's keys in order to process each of them.

We'll cover the following...

We’ve seen that for-loops are great for looping through arrays. There’s another type of loop for objects, the for-in loop.

Press + to interact
let jon = {
firstName: 'Jon',
lastName: 'Smith',
age: 34,
profession: 'Developer',
married: true
};
for(let key in jon) {
console.log(key, ':', jon[key]);
}

We start it out as a standard for-loop.

for() {
		// body
}
...