Chrome Developer Console Can't Run JS Loops - Stack Overflow

In the chrome console, I can't run any loops. Why is this?For example, the following will give a s

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744091255a4557122.html

相关推荐

  • Chrome Developer Console Can't Run JS Loops - Stack Overflow

    In the chrome console, I can't run any loops. Why is this?For example, the following will give a s

    9天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信