JavaScript for...in Statement
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
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.
Desktop





Tablets & Mobile





