js map 循环
发布于 4 年前 作者 gocpplua 3378 次预览 最后一次回复是 4 年前 来自 分享
// --target es6
// error TS2569: Type ‘IterableIterator<string>’ is not an array type or a string type. Use compiler option ‘–downlevelIteration’ to allow iterating of iterators.
let map= new Map<string, string>();
map.set("a1","1");
map.set("a2","2");
map.set("a3","3");
map.forEach((value , key) =>{
if(value == 'a1'){
return;
}
console.log(key) // output: a1 a2 a3
});
for (const i of map.values()) {
if(i == '1'){
break;
}
console.log(i) // not run here
}
1 回复
请检查你的TypeScript的target是不是es6?如果是es6以下版本,请这样做(在ts.config):