How do I loop through or enumerate a JavaScript object?

Created by levikLinked to 30m issues across 272 teams


You can loop through a JavaScript object using a loop. This loop will iterate over all the enumerable properties of an object. For example:

const myObject = { name: 'John', age: 25, city: 'New York' }; for (const key in myObject) { console.log(`${key}: ${myObject[key]}`); }

The above code will output the following:

name: John age: 25 city: New York
We use cookies to personalize content
run ads, and analyze traffic.