TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
JavaScript / Chapter 8 of 60~12 min • Beginner
Chapter 08JavaScript

Loops

Loops repeat work. for...of iterates over values in an iterable such as an array. A traditional for loop uses initialization, a condition and an update. In asynchronous tests, await sequential actions inside for...of when order matters.

How it works

Step-by-step walkthrough

  1. Create an array
  2. Iterate over its values
  3. Print each browser name

Example

JavaScript
const browsers = ['chromium', 'firefox', 'webkit'];
for (const browser of browsers) {
  console.log(browser);
}
Expected result: Three browser names on separate lines
💡 Point to remember
Avoid async callbacks in forEach when you need to await completion.

✎ Your practice task

Add a fourth item and run the loop again.

Knowledge check

Which loop directly iterates array values?

🌐 Continue learning