let arr = [2, 5, 8, 1, 4] // filter 實現 返回 數組 let result = arr.filter(item => { return item > 10 }).length > 0 // find 實現 返回所匹配的那一項 let result = arr.find(item => { return item > 10 }) !== undefined // some 實現 返回true false let result = arr.some(item => { return item > 10 })
addChannelCart: function () { const that = this; // console.log(that.data.warehouse_id, '添加購物車==>warehouse_id') let result = that.data.cart_list.some(item => { return item.warehouse_id == that.data.warehouse_id }) console.log(result, 'result') if (!result) { wx.showToast({ title: '', icon: 'none' }) } return; if (!wx.getStorageSync('brand_shop_id')) { wx.showToast({ title: '添加購物車無brand_shop_id', }) }