In the chrome console, I can't run any loops. Why is this?
For example, the following will give a syntax error of "Expected '('"
for each (var item in [1, 2, 3]) alert(item)
In the chrome console, I can't run any loops. Why is this?
For example, the following will give a syntax error of "Expected '('"
for each (var item in [1, 2, 3]) alert(item)
Share
Improve this question
asked Aug 8, 2010 at 17:06
VerhogenVerhogen
28.7k35 gold badges93 silver badges109 bronze badges
2 Answers
Reset to default 5each
isn't a Javascript keyword. See the W3Schools page on Javascript's for
statement for reference.
Try the following:
for ( var item in [1,2,3] ) alert(item)
It's been a long time since the question is posted. I'm a new user and just found out one more way or a better way to do it.
[1, 2, 3].forEach( el => alert(el))
Hope this also may help someone.