VOOZH about

URL: https://www.geeksforgeeks.org/javascript/how-to-iterate-over-a-javascript-object/

⇱ Iterate over a JavaScript object - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Iterate over a JavaScript object

Last Updated : 14 Oct, 2025

Iteration involves looping through the object's properties one by one. Depending on the method used, you can access and manipulate different levels of properties efficiently. Here are several methods.

[Approach 1]: Using for...in Loop

A for..in loop iterates over all enumerable properties of an object, including inherited ones. Use hasOwnProperty() to filter only the object’s own properties, and access each value using the key.


Output
book Sherlock Holmes
author Arthur Conan Doyle
genre Mystery

Syntax:

for (let key in exampleObj) { 
if (exampleObj.hasOwnProperty(key)) { 
 value = exampleObj[key]; 
 console.log(key, value); 
 }
}

[Approach 2]: Using Object.entries() and map()

Object.entries()returns an array of an object’s own enumerable key-value pairs. Use map() to access each pair, where index 0 is the key and index 1 is the value.


Output
book Sherlock Holmes
author Arthur Conan Doyle
genre Mystery

Syntax:

Object.entries(exampleObj).map(entry => { 
let key = entry[0];
let value = entry[1];
console.log(key, value);
});

[Approach 3]: Using forEach() and object.keys() Method

object.keys() Method returns an array of keys of the object and forEach() method is an array method that allows you to iterate over each element in the array.


Output
book: Sherlock Holmes
author: Arthur Conan Doyle
genre: Mystery
Comment