TypeError: person is not iterable关于for of报错

TypeError: person is not iterable关于for of报错

因为普通对象不可迭代,而for…of 循环仅适用于迭代。
那么可以用for of 遍历什么呢?
for…of 允许你遍历 Arrays(数组), Strings(字符串), Maps(映射), Sets(集合)等可迭代的数据结构等。

语法

for (variable of iterable) {
    statement
}

variable:每个迭代的属性值被分配给该变量。
iterable:一个具有可枚举属性并且可以迭代的对象。
查看js的各自遍历的用法及实例

发布了29 篇原创文章 · 获赞 8 · 访问量 1034

猜你喜欢

转载自blog.csdn.net/weixin_44523860/article/details/104069173