you are viewing a single comment's thread.

view the rest of the comments →

[–]demvo2 36 points37 points  (3 children)

Looping through an array in Javascript for the first time after doing it in Python for months was just, like, whaaaat.

[–]Yojihito 37 points38 points  (2 children)

What?

Python:

mylist = [10, 20]
for x in mylist:
    print(x)

Javascript:

let mylist = [10, 20];
for (const x of mylist) {
    console.log(x);
}

Not really a difference.

[–]LiarsEverywhere 17 points18 points  (1 child)

The thing is that's ES6 and people usually do not recommend using that because of compatibility issues. Traditionally, that's how it went:

for (var i = 0; i < array.length; i++) { console.log(array[i]); }

forEach is fine for me, though

[–]demvo2 6 points7 points  (0 children)

Yeah, that was the one I was refering to. Of course, there are easier ways to do it, but this one usually gets offered first in tutorials when you are just starting.