【发布时间】:2021-10-11 04:14:10
【问题描述】:
在我的方法中,我根据不同商店的可用性显示产品详细信息列表。为此,我正在使用这种方法。
for (let i = 0; i < this.prodList.length; i++) {
let setContent = false;
for (let j = 0; j < res.data.length; j++) {
if (res.data[j].product === this.prodList[i].value) {
this.detailList[i] = {
product: this.prodList[i].value,
content: res.data[j].content,
shopName: res.data[j].shopName
};
this.formData.addressList[i] = {
product: this.prodList[i].value,
content: res.data[j].content,
shopName: res.data[j].shopName
};
setContent = true;
break;
}
}
}
如何使用 find 或 filter 代替 for 循环?
【问题讨论】:
-
如果您也可以添加数据数组,那将很容易回答和理解。可能有一些简单直接的方法可以解决这个问题。 ??????
标签: javascript arrays ecmascript-6