Back
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 }
String[] myStringArray = {"Hello", "World"};
for (String s : myStringArray) {
// Do something
}
Can you do the same in JavaScript?
There are several ways to loop through an array in JavaScript one of them I am mentioning here:-
var myStringArray = ["Hello","World"]; var arrayLength = myStringArray.length; for (var i = 0; i < arrayLength; i++) { console.log(myStringArray[i]); //Do something }
var myStringArray = ["Hello","World"];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) { console.log(myStringArray[i]);
//Do something
31k questions
32.8k answers
501 comments
693 users