在小程序操作数组中 遇到了Cannot read property ‘concat’ of undefined这个错误
let obj = {
"goodsId": goodsId,
"platformId": platformId
}
// 在这里提示我 concat of undefined
let arr = this.data.goodsIdList.concat(JSON.stringify(obj))
let arrSet = new Set(arr)
this.setData({
goodsIdList: Array.from(arrSet)
})
经查,当需要被合并的数组 也就是this.data.goodsIdList是undefined时,会出现Cannot read property ‘concat’ of undefined这个错误,push 也是空的