# Loop through an array of objects in JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Jul 22, 2021, updated Jun 10, 2023. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-iterate-array-of-objects

> A quick guide to learn how to loop through an array containing objects and print each object's properties in JavaScript.

In JavaScript, you can loop through an array of objects using the [`forEach()`](https://attacomsian.com/blog/javascript-foreach#looping-through-arrays) method combined with the [`for...in`](https://attacomsian.com/blog/for-in-loop-in-javascript) loop.

Consider the following code example that illustrates how to iterate over an array containing objects and print the properties of each object:

```javascript
const mobiles = [
  {
    brand: 'Samsung',
    model: 'Galaxy Note 9'
  },
  {
    brand: 'Google',
    model: 'Pixel 3'
  },
  {
    brand: 'Apple',
    model: 'iPhone X'
  }
]

mobiles.forEach(mobile => {
  for (let key in mobile) {
    console.log(`${key}: ${mobile[key]}`)
  }
})
```

When you execute the above code, you will see the following output:

```bash
brand: Samsung
model: Galaxy Note 9
brand: Google
model: Pixel 3
brand: Apple
model: iPhone X
```

In this code, the outer `forEach()` loop is used to iterate through the array of objects. Inside this loop, the `for...in` loop is used to [iterate through the properties](https://attacomsian.com/blog/javascript-iterate-objects) of each individual object.
