JavaScript Code

How to iterate over elements of array using For Loop?

Problem Statement

given an array of elements, write a JavaScript program to iterate over the elements of the array using for loop


for loop is used to repeatedly run a block of code as long as the loop condition evaluates to true. we can use a variable and increment it during iterations to simulate the indices of given array. the condition can be that the index is less than the length of array


let fruits = ['apple', 'banana', 'cherry' ]

for (let index = 0; index < fruits.length; index++ ) {

copyright @2022