Search⌘ K
AI Features

for-in loops

Explore how to use for-in loops in JavaScript to iterate through object keys. Understand the syntax and how bracket notation lets you access each property dynamically, enhancing your ability to work with objects in your code.

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.

Node.js
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
}
...