JavaScript - Iterate Over an Array Last Updated : 10 Jan, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report JavaScript for Loop can be used to iterate over an array. The for loop runs for the length of the array and in each iteration it executes the code defined inside. We can access the array elements using the index number.1. Using for...of LoopThe for…of loop iterates over the values of an iterable object such as an array. It is a better choice for traversing items of iterables compared to traditional for and for in loops, especially when we have a break or continue statements. JavaScript let a = [10, 20, 30, 40, 50]; for (let item of a) { console.log(item); } Output10 20 30 40 50 2. Using forEach() MethodThe forEach() Method calls the provided function once for every array element in the order. It does not return a new array and does not modify the original array. It’s commonly used for iteration and performing actions on each array element. JavaScript let a = [10, 20, 30, 40, 50]; a.forEach((item) => { console.log(item); }); Output10 20 30 40 50 3. Using for...in LoopA for...in Loop iterates over the enumerable properties of an object, allowing you to access each key or property name in turn. The for…in loop can also works to iterate over the properties of an array if maintaining index order is important. JavaScript let a = [10, 20, 30, 40, 50]; for (let i in a) { console.log(a[i]); } Output10 20 30 40 50 4. Using for loopThe for Loop executes a set of instructions repeatedly until the given condition becomes false. It is similar to loops in other languages like C/C++, Java, etc. JavaScript let a = [10, 20, 30, 40, 50]; for (let i = 0; i < a.length; i++) { console.log(a[i]); } Output10 20 30 40 50 5. Using while LoopA while loop in JavaScript is a control flow statement that allows the code to be executed repeatedly based on the given boolean condition. JavaScript let a = [10, 20, 30, 40, 50]; let i = 0; while (i < a.length) { console.log(a[i]); i++; } Output10 20 30 40 50 6. Using do...while LoopThe do...while Loop in JavaScript is a control structure where the code executes repeatedly based on a given boolean condition. The do...while loop executes the code at least once. JavaScript let a = [10, 20, 30, 40, 50]; let i = 0; do { console.log(a[i]); i++; } while (i < a.length); Output10 20 30 40 50 Comment More infoAdvertise with us Next Article JavaScript - Iterate Over an Array V Vineet Joshi Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-Questions +1 More Similar Reads Java Program to Iterate Over Arrays Using for and for-each Loop In Java, arrays are a collection of elements of the same type. To access and manipulate elements, we can use iteration techniques such as the for loop and for-each loop (also known as the enhanced for loop).Program to Iterate Over Arrays Using for and for-each Loop in JavaIn the below example, we wi 1 min read Java - Loop Through an Array In Java, looping through an array or Iterating over arrays means accessing the elements of the array one by one. We have multiple ways to loop through an array in Java. Example 1: Here, we are using the most simple method i.e. using for loop to loop through an array.Java// Java program to loop throu 3 min read Java for loop vs Enhanced for loop In Java, loops are fundamental constructs for iterating over data structures or repeating blocks of code. Two commonly used loops are the for loop and the enhanced for loop. While they serve similar purposes, their applications and usage vary based on the scenario.for loop vs Enhanced for loopBelow 4 min read Java Program to Print the Elements of an Array An array is a data structure that stores a collection of like-typed variables in contiguous memory allocation. Once created, the size of an array in Java cannot be changed. It's important to note that arrays in Java function differently than they do in C/C++As you see, the array of size 9 holds elem 6 min read ArrayDeque iterator() Method in Java The Java.util.ArrayDeque.iterator() method is used to return an iterator of the elements of the ArrayDeque. Syntax: Iterator iterate_value = Array_Deque.iterator(); Parameters: The method does not take any parameter. Return Value: The method iterates over the elements of the deque and returns the va 2 min read Like