下面的代码报错TpyeError:data.map is not a function.
let nameList = data.map(item => item.name);
原因1:data不是数组;
解决方法:将data转换成数组
let data = Array.from(data);
- map不能遍历HTMLCollection类型的数据,必须先将HTMLCollection转换成array。
- 接着使用for循环,发现能正常运行。
参考博客:记录React JS TypeError: data.map is not a function https://blog.csdn.net/weixin_44371012/article/details/89716413
.map() is not a function【js报错】 https://www.cnblogs.com/jaycethanks/p/13491512.html