This foreach loop is faster because the local variable that stores the value of the element in the array is faster to access than an element in the array. The forloop is faster than the foreach loop if the array must only be accessed once per iteration.
Read moreWhat is for loop and example?
A “For” Loop is used to repeat a specific block of code a known number of times . For example, if we want to check the grade of every student in the class, we loop from 1 to that number. When the number of times is not known before hand, we use a “While” loop.
Read moreWhat do you mean by for each loop?
Foreach loop (or for each loop) is a control flow statement for traversing items in a collection . Foreach is usually used in place of a standard for loop statement.
Read moreWhat is the difference between for in loop and for of loop?
Both for..in and for..of are looping constructs which are used to iterate over data structures. The only difference between them is the entities they iterate over: for..in iterates over all enumerable property keys of an object . for..of iterates over the values of an iterable object .
Read more