How to Traverse Array of Objects and Access the Properties in JavaScript? Last Updated : 07 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Here are the various methods to traverse an array of objects and access the properties in JavaScript1. Using for…in loopThe for...in loop is used to iterate over the enumerable properties of an object. JavaScript const a = [ {name: 'Saritha', sub: 'Maths'}, {name: 'Sarthak', sub: 'Science'}, {name: 'Sneha', sub: 'Social'} ] a.forEach(teacher => { for (let value in teacher) { console.log(`${teacher[value]}`) } }) OutputSaritha Maths Sarthak Science Sneha Social In this example: forEach() goes through each object in the array.for...in loops through the properties (name, sub) of each teacher object.teacher[value] accesses and logs the value of each property.2. Using forEach() MethodThe forEach() method executes a provided function once for each array element. JavaScript const a = [{ x:1 }, { x: 2 }, { x: 3 }]; a.forEach((element, index, array) => { console.log(element.x); }); Output1 2 3 In this example:forEach() is used to iterate over each object in the arr.element represents the current object (e.g., { x: 1 }, { x: 2 }).element.x accesses and logs the x property of each object.3. Using Object.keys() MethodObject.keys() returns an array of a given object's own enumerable property names (keys). JavaScript const a = [ {name: 'Saritha', sub: 'Maths'}, {name: 'Sarthak', sub: 'Science'}, {name: 'Sneha', sub: 'Social'} ] for (let teacher in a) { for (let key in a[teacher]) { console.log(a[teacher][key]); } } OutputSaritha Maths Sarthak Science Sneha Social In this example: The outer for...in loop iterates over the array, where each teacher is the index of an object in the array.The inner for...in loop iterates over the keys (name, subject) of each teacher object.a[teacher][key] accesses and logs the value of each property (like 'Saritha', 'Maths', etc.).4. Using object.values() MethodObject.values() returns an array of a given object's own enumerable property values. JavaScript const a = [ {name: 'Saritha', sub: 'Maths'}, {name: 'Sarthak', sub: 'Science'}, {name: 'Sneha', sub: 'Social'} ] for (const value of Object.values(a)) { for (let v in value) { console.log(value[v]); } } OutputSaritha Maths Sarthak Science Sneha Social In this example:Object.values(a) returns an array of the teacher objects.for...of loops through each teacher object.for...in loops over the properties (name, subject) of each teacher object.value[v] accesses and logs the values of the properties (name and subject).5. Using the object.entries() MethodThe Object.entries() method in JavaScript returns an array consisting of enumerable property [key, value] pairs of the object. JavaScript const a = [ {name: 'Saritha', sub: 'Maths'}, {name: 'Sarthak', sub: 'Science'}, {name: 'Sneha', sub: 'Social'} ] for (const entry of Object.entries(a)) { for (let value in entry[1]) { console.log(entry[1][value]); } } OutputSaritha Maths Sarthak Science Sneha Social In this example:Object.entries(a) returns an array of [index, teacher] pairs.for...of loops through each pair, and for...in accesses the properties (name, subject) of each teacher object.entry[1][value] logs the property values. Comment More infoAdvertise with us Next Article How to read properties of an Object in JavaScript ? K krishnav4 Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Technical Scripter 2022 javascript-array JavaScript-DSA JavaScript-Questions +3 More Similar Reads How to read properties of an Object in JavaScript ? Objects in JavaScript, it is the most important data type and forms the building blocks for modern JavaScript. These objects are quite different from JavaScriptâs primitive data-types(Number, String, Boolean, null, undefined, and symbol) in the sense that these primitive data-types all store a singl 2 min read How to Access Array of Objects in JavaScript ? Accessing an array of objects in JavaScript is a common task that involves retrieving and manipulating data stored within each object. This is essential when working with structured data, allowing developers to easily extract, update, or process information from multiple objects within an array.How 4 min read How to add and remove properties from objects in JavaScript ? We will try to understand how to add properties to an object and how to add or remove properties from an object in JavaScript.Before we go and see the addition and removal of properties from an object let us first understand the basics of an object in JavaScript.Object:An object in JavaScript is a c 6 min read How to get dynamic access to an object property in JavaScript ? In JavaScript, an object is a collection of properties, where each property consists of a key-value pair. Objects are a fundamental data type in JavaScript. You can create an object in JavaScript in the following ways: By using the object literal notation, which is a comma-separated list of key-valu 7 min read How to Return an Array of Unique Objects in JavaScript ? Returning an array of unique objects consists of creating a new array that contains unique elements from an original array. We have been given an array of objects, our task is to extract or return an array that consists of unique objects using JavaScript approaches. There are various approaches thro 5 min read How to create object properties in JavaScript ? JavaScript is built on an object-oriented framework. An object is a collection of properties, where each property links a key to a value. These properties are not in any specific order. The value of a JavaScript property can be a method (function). Object properties can be updated, modified, added, 4 min read Like