Syntax

JavaScript For...in Loop Syntax

In JavaScript, for...in loop: loops over an object's keys — for (const key in obj) { ... }

Quick Answer

Syntax
for (const key in obj) { ... }
JavaScriptSyntax

For...in Loop

Code example
for (const key in obj) { ... }

Loops over an object's keys.

Learn More

How to for...in loop in JavaScript

  1. Open your JavaScript file or editor.
  2. Copy the example, then replace its sample names and values for your code.

JavaScript For...in Loop Syntax

Use for (const key in obj) { ... }.

Related Syntax References

Frequently asked questions

What is the JavaScript syntax for for...in loop?

Use this pattern: for (const key in obj) { ... }

Can I copy this JavaScript code example?

Yes. Use Copy code and adapt the example to your program.

Is this JavaScript syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify