var goodlist = wx.getStorageSync('goodlist');
var orderlist = wx.getStorageSync('orderlist');
for (let i = 0; i < goodlist.length; i++) {
for (let ii = 0; ii < orderlist.length; ii++) {
if (goodlist[i].goodsId = orderlist[ii]._id) {
goodlist.splice(i, 1);
wx.setStorageSync('goodlist', goodlist);
}
}
};
wx.removeStorageSync('orderlist');
判断相等是双等号或者三等
goodlist.filter(v=>!orderlist.find(u=>u._id==v.goodsId))
这地方错了,===
在for循环内删除,你的数组长度就变了,也会影响当前索引的指向。
const goodList = wx.getStorageSync('goodlist') || [];
const orderList = wx.getStorageSync('orderlist') || [];
const orderIdMap = {};
// 用map进行匹配,性能好,复杂度是O(1)
orderList.forEach((order) => {
orderIdMap[order._id] = true;
});
const newList = goodList.filter((good) => !(good.goodsId in orderIdMap));
console.log(newList);