+ 1

For (i in array) vs for (i = 0;i<array.length;i++)

Following a tutorial recently I noticed the use of both ways of using the for loop : For (i in array) vs for (i = 0;i<array.length;i++) but is there any difference between these?

8th Nov 2017, 12:21 PM
Austris Otersons-Andersons
Austris Otersons-Andersons - avatar
2 Answers
+ 11
in the second one you can access the index of the array (i) which might be very helpful in some situations
8th Nov 2017, 12:24 PM
Kamil
Kamil - avatar
+ 1
here is also forEach ... and for of in ES6
8th Nov 2017, 8:52 PM
Rose Sevenyears
Rose  Sevenyears - avatar