Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

In Java you can use a for loop to traverse objects in an array as follows:

String[] myStringArray = {"Hello", "World"};

for (String s : myStringArray) { 

// Do something 

}

Can you do the same in JavaScript?

1 Answer

0 votes
by (106k points)

There are several ways to loop through an array in JavaScript one of them I am mentioning here:-

You can use the sequential for loop for this below is the code for the same:

var myStringArray = ["Hello","World"]; 

var arrayLength = myStringArray.length; 

for (var i = 0; i < arrayLength; i++) { console.log(myStringArray[i]); 

//Do something 

}

Related questions

0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...