简体   繁体   English

Chrome浏览器中的for-of循环

[英]For-of loop in Chrome browser

Firefox browser console is returning the expected answer. Firefox浏览器控制台正在返回预期的答案。 But when I run the below code in Chrome console it is returning back Unexpected token [ . 但是,当我在Chrome控制台中运行以下代码时,它会返回Unexpected token [ Version of my Chrome browser is 44, while map and for...of methods are compatible from version 38. Why does the Chrome console cause an error? 我的Chrome浏览器版本为44,而mapfor...of方法与版本38兼容。为什么Chrome控制台会导致错误?

var map = new Map();
map.set(3, "Fizz");
map.set(5, "Buzz");
for (var [key, value] of map.entries()) {
    if (6 % key == 0) console.log(key);
}

Use ScratchJS , Google Chrome does not seem to support all ECMA6. 使用ScratchJS ,谷歌浏览器似乎并不支持所有ECMA6。 You are right for...of should be supported and it is indeed supported. 您的观点是for...of应该受到支持,的确得到了支持。 What is not supported is the unpacking of values. 不支持将值拆包。 Check the compatibility table at the index destructuring, assignement , only Chrome 49 seems to have partial support for it. 在索引destructuring, assignement处检查兼容性表 ,只有Chrome 49似乎部分支持它。

If you try to remove the unpacking it will work. 如果您尝试拆开包装,它将可以使用。

 var map = new Map();
 map.set(3, "Fizz");
 map.set(5, "Buzz");
 for (var value of map.entries()) {
    console.log(value[0]);
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM