# How to iterate over object properties in JavaScript

> Learn how to iterate over the properties of a JavaScript object, since map and forEach do not work on objects, using a for...in loop or Object.entries().

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2019-11-02 | Updated: 2020-04-05 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/how-to-iterate-object-properties-javascript/

If you have an object, you can't just iterate it using `map()`, `forEach()` or a `for..of` loop.

You will get errors:

```js
const items = {
  'first': new Date(),
  'second': 2,
  'third': 'test'
}
```

`map()` will give you `TypeError: items.map is not a function`:

```js
items.map(item => {})
```

`forEach()` will give you `TypeError: items.forEach is not a function`:

```js
items.forEach(item => {})
```

`for..of` will give you `TypeError: items is not iterable`:

```js
for (const item of items) {}
```

So, what can you do to iterate?

`for..in` is a simpler way:

```js
for (const item in items) {
  console.log(item)
}
```

You can also call **`Object.entries()`** to generate an array with all its enumerable properties, and loop through that, using any of the above methods:

```js
Object.entries(items).map(item => {
  console.log(item)
})

Object.entries(items).forEach(item => {
  console.log(item)
})

for (const item of Object.entries(items)) {
  console.log(item)
}
```
