js使用map,JS中String转Json方法

 js使用map

 

使用map时遇到的报错:

下面的代码报错TypeError: data.map is not a function

let nameList = data.map(item => item.name);

原因1:data不是数组

解决方法:将data转换为数组

let data = Array.from(data);

 

 

 正常使用:

复制代码
 getData() {
            // 调用接口方法
            getlistInspectionnum().then(response => {
                console.log("######234#######")
                // console.log(response.length)
                // console.log("23242:" + response[0]["deviceCompleted"])
                // if (response.length != 0) {
                //     this.mychart3_x_data_arr.push(response[0]["deviceCompleted"])
                // } else {
                //     this.mychart3_x_data_arr.push(0)
                // }
                // this.mychart3_x_data_arr.push(response[0]["deviceCompleted"])

                this.mychart3_x_data_arr = response.map(item => {
                    return item.deviceCompleted
                }
               
                );
                // console.log(mychart3_x_data_arr);

                this.mychart3_y_ywc_data_arr = response.map(item => {
                    return item.inspectionName
                });
                this.initOption();
            })
           

        }
复制代码

 

 

 

JS中String转Json方法


JSON.parse(jsonstr); //可以将json字符串转换成json对象

this
.inline_I = JSON.parse(response.deviceData)["Current"]; this.inline_U = JSON.parse(response.deviceData)["Voltage"];

 

 
 
 
 
posted @   小小仓鼠  阅读(32)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
点击右上角即可分享
微信分享提示