Skip to content

循环

JavaScript 支持不同类型的循环:

  • for - 多次遍历代码块

  • for/in - 遍历对象属性

  • while - 当指定条件为 true 时循环一段代码块

  • do/while - 当指定条件为 true 时循环一段代码块

  • for of 语句循环遍历可迭代对象的值

break 语句“跳出”循环。

continue 语句“跳过”循环中的一个迭代。

for of

for...of 循环可以使用的范围包括:

  1. 数组
  2. Set
  3. Map
  4. 类数组对象,如 arguments 对象、DOM NodeList 对象
  5. Generator 对象
  6. 字符串