ES6 代码优化:使用 reduce 统计数组元素数量
const sum = arr.reduce((sum, item) => { if (val === item.materialCode) { sum++; if (sum > 1) { arr[index] = { rowId: getRandomId(), processId: store.processId, projectId: props.productInfo.projectId }; return proxy.$modal.msgError('当前自制件已选择'); } } return sum; }, 0);
原文地址: https://www.cveoy.top/t/topic/qAzl 著作权归作者所有。请勿转载和采集!