Open In App

How to Iterate Over the Elements of an Array in JavaScript ?

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In JavaScript, you can iterate over the elements of an array using various methods. Here are some common ways:

  • For Loop:
    • The traditional for loop allows you to iterate over the array elements by using the array’s length property.
  • For…of Loop:
    • The for...of loop is a more concise way to iterate over the elements of an array. It directly gives you the values of the elements without the need for an index.
  • forEach Method:
    • The forEach method is a built-in method for arrays. It executes a provided function once for each array element.
  • Map Method:
    • The map method is used to create a new array by applying a function to each element of an existing array.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads