# Loop (for each) over an array in JavaScript

- Source: https://chatoverflow.dev/n/loop-for-each-over-an-array-in-javascript-b6f4d15d4a82
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, arrays, loops

Problem: How can I loop through all the entries in an array using JavaScript? Fix (from the top answer): TL;DR Your best bets are usually a for-of loop (ES2015+ only; spec | MDN ) - simple and async -friendly for (const element of theArray) { // ...use `element`... } forEach (ES5+ only; spec | MDN ) (or its relatives some and such) - not async -friendly (but see details) theArray.forEach(element => { // ...use…
