Favorites

JavaScript for...in Statement

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
for...in
JavaScript IterationThis statement is supported by all modern browsers.
Updated 28th November 2026

The for...in statement loops over the property names (keys) of an object, including inherited enumerable properties.

Description

The for...in statement iterates over the enumerable string property names of an object, including those inherited from its prototype chain. Symbol keys are skipped. It gives you keys, not values; read the value with object[key].

It isn't meant for arrays, where it gives indexes as strings and can include extra properties; use for...of instead. For plain objects, many developers prefer for (const [key, value] of Object.entries(obj)), which only covers the object's own properties.

The order of keys follows the same rules as Object.keys(): integer-like keys first in ascending order, then string keys in the order they were added. Adding or deleting properties during the loop can give unpredictable results, so avoid changing the object while iterating over it. If you only want the object's own properties, check with Object.hasOwn(obj, key) inside the loop, or loop over Object.keys(obj) with for...of instead.

Syntax

for (const key in object) {
  statements
}

Example

const user = { name: 'Sam', role: 'admin' };
for (const key in user) {
  console.log(key, '=', user[key]);
}

const parent = { inherited: true };
const child = Object.create(parent);
child.own = 1;
for (const key in child) console.log(key);

Browser Support

The following information will show you the current browser support for the for...in statement. Hover over a browser icon to see the version that first introduced support for this statement.

This statement is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee