Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me how I can able to loop through all the entries present in an array? I was tried with forEach, but it is not working. Can anyone help me with this?

1 Answer

0 votes
by (26.7k points)

Basically, there are multiple ways to do that:

Using forEach:

var arr = ["a", "b", "c"];

arr.forEach(function(entry) {

    console.log(entry);

});

Using for:

var i;

var arr = ["a", "b", "c"];

for (i = 0; i< a.length; ++i) {

    console.log(arr[i]);

}

You can go for simple "For" loop.

I hope this will help.

Want to know more about Java? Watch this video on Java Tutorial | Java Course:

Want to become a Java expert? join Java Training now!!

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jan 27, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer
asked Mar 4, 2021 in Java by dante07 (13.1k points)

Browse Categories

...