admin 管理员组

文章数量: 1086019

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
Add a ment  | 

2 Answers 2

Reset to default 5

each 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.

本文标签: Chrome Developer Console Can39t Run JS LoopsStack Overflow