JavaScript Code

How to iterate over elements of array using While Loop?

Problem Statement

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


while 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' ]

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

copyright @2022