for...in、for...of区别

86 阅读1分钟

for...in

  • 遍历得到key
  • 只能遍历可枚举数据:数组、字符串、对象

for...of

  • 遍历得到value
  • 只能遍历可迭代数据:数组、字符串、Map、Set