loader

Loading

CoderrShyam logo

CoderrShyam

HomeAboutContactBlogTutorials
LoginSignup

Introduction

Quick StartWhat is JavaScriptHistory of JavaScript

Setup

Node.js InstallationVisual Studio Code

Basics

Syntax & Comments
Variables
Functions
JavaScript StringsJavaScripit ArraysLoops with ArraysMap, Filter, and ReduceDate in JavaScriptMath in JavaScriptNumber in JavaScriptBoolean in JavaScript

Advanced

CoderrShyam logo

CoderrShyam

HomeAboutContactBlogTutorials
LoginSignup
TutorialsJavaScript TutorialObjectsLoops with Arrays

Loops with Arrays

In this tutorial, we will learn how to use loops to iterate over arrays in JavaScript.

In JavaScript, arrays are used to store multiple values in a single variable. They are a special type of object that can hold multiple values at once.

Basic Syntax

Here is the basic syntax for creating an array in JavaScript:

let fruits = ["apple", "banana", "cherry"];

In this example, we have created an array called fruits that contains three elements: 'apple', 'banana', and 'cherry'.

Using Loops with Arrays

There are several ways to iterate over the elements of an array in JavaScript. Some of them are:

for Loop

The for loop is a common way to iterate over the elements of an array. Here is an example:

main.js
let fruits = ["apple", "banana", "cherry"];

for (let i = 0; i < fruits.length; i++) {
  console.log(fruits[i]);
}

This will output:

apple
banana
cherry

forEach Method

The forEach method is another way to iterate over the elements of an array. Here is an example:

main.js
let fruits = ["apple", "banana", "cherry"];

fruits.forEach(function (fruit) {
  console.log(fruit);
});

This will output:

apple
banana
cherry

for...of Loop

The for...of loop is a modern way to iterate over the elements of an array. Here is an example:

main.js
let fruits = ["apple", "banana", "cherry"];

for (let fruit of fruits) {
  console.log(fruit);
}

This will output:

apple
banana
cherry

Conclusion

  • In JavaScript, arrays are used to store multiple values in a single variable.
  • There are several ways to iterate over the elements of an array, such as using a for loop, the forEach method, or the for...of loop.

How is this guide?

February 26th, 2026

JavaScripit Arrays

Arrays are used to store multiple values in a single variable. They are a special type of object that can hold multiple values at once.

Map, Filter, and Reduce

In this tutorial, we will learn how to use the map, filter, and reduce methods in JavaScript to manipulate arrays.

© 2026CoderrShyamAll Rights Reserved.

On this page

Basic Syntax
Using Loops with Arrays
for Loop
forEach Method
for...of Loop
Conclusion
Follow us on GitHub