最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin8浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论