for...in、for...of、for await...of
for in of ... await
2023-06-13 09:17:41 时间
处世应当谦虚,切忌轻人傲世。——佚名
简单说下区别:
for...in
遍历出来的是key
var obj = {a:1, b:2, c:3};
for (var prop in obj) {
console.log("obj." + prop + " = " + obj[prop]);
}
// Output:
// "obj.a = 1"
// "obj.b = 2"
// "obj.c = 3"
for...of
遍历出来的是元素
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
// Expected output: "a"
// Expected output: "b"
// Expected output: "c"
for await...of
和for...of
差不多,但支持遍历由Promise
组成的可迭代对象(如数组),使用时会自动await
直到Promise
执行结束才执行
var asyncIterable = {
[Symbol.asyncIterator]() {
return {
i: 0,
next() {
if (this.i < 3) {
return Promise.resolve({ value: this.i++, done: false });
}
return Promise.resolve({ done: true });
}
};
}
};
(async function() {
for await (num of asyncIterable) {
console.log(num);
}
})();
// 0
// 1
// 2
相关文章
- Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
- js for in for of 的区别
- Parallels Desktop 18 for Mac永久 授权 激活-让你在Mac上轻松运行Windows
- 视频编辑软件Premiere Pro 2021 for Mac(pr 2021)
- ORA-01719: outer join operator (+) not allowed in operand of OR or IN ORACLE 报错 故障修复 远程处理
- ORA-29959: error in the execution of the string routine for one or more of the index partitions ORACLE 报错 故障修复 远程处理
- ORA-32036: unsupported case for inlining of query name in WITH clause ORACLE 报错 故障修复 远程处理
- ORA-32416: one or more commit SCN-based materialized view logs are not in consistent state for fast refresh ORACLE 报错 故障修复 远程处理
- ORA-32484: duplicate name found in cycle column list for CYCLE clause of WITH clause ORACLE 报错 故障修复 远程处理
- MySQL Error number: 3105; Symbol: ER_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: MY-011178; Symbol: ER_SEMISYNC_MISSING_MAGIC_NO_FOR_SEMISYNC_PKT; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-14279: index mismatch for tables in ALTER TABLE EXCHANGE SUBPARTITION ORACLE 报错 故障修复 远程处理
- ORA-14609: Tablespace was not specified for the previous lob segments of column string in template but is specified for string ORACLE 报错 故障修复 远程处理
- ORA-14645: STORE IN clause cannot be specified for Range List objects ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-013522; Symbol: ER_SCHEMA_NAME_IN_UPPER_CASE_NOT_ALLOWED_FOR_FK; SQLSTATE: HY000 报错 故障修复 远程处理
- Linux UBIFS File System:A Solid Foundation for Network Security.(linuxubifs)
- Monitoring Redis Keys for Improved Performance(redis监听key)
- Oracle中使用EXISTS代替IN(oracle替换in)
- 条件查询手把手教你:用 Oracle 多重IN 条件查询(oracle多重in)
- Exploring the Power of Nested Loops in Oracle for Maximum Efficiency(oracle循环嵌套)
- MySQL中使用IN操作符的查询效率分析(mysql中in的效率)
- javascript下for(in)语句获得所有style的【scrollbar】滚动条样式内容
- php获取ip的三个属性区别介绍(HTTP_X_FORWARDED_FOR,HTTP_VIA,REMOTE_ADDR)