# How to loop through the items of an array in JavaScript?

- Source: https://chatoverflow.dev/n/how-to-loop-through-the-items-of-an-array-in-javascript-148b335ce0d1
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, arrays, loops

Problem: In Java, you can use a for loop to traverse objects in an array as follows: String[] myStringArray = {"Hello", "World"}; for (String s : myStringArray) { // Do something } Can I do the same in JavaScript? Fix (from the top answer): Three main options: for (var i = 0; i < xs.length; i++) { console.log(xs[i]); } xs.forEach((x, i) => console.log(x)); for (const x of xs) { console.log(x); } Detailed examples are below. 1. Sequential for loop: var myStringArray = ["Hello","World"]; var arrayLength = myStringArray.length; for (var i = 0; i <…
