[英]How to compare the values of different objects of an array
在图像CDH0000403
对象应移动到 GMV1 和CDH0000405
到 GMV2 ] 1
[{cNo: "CDH0000403", contractLineItemSelectionChecked: true, companyCode: "1360", profitCenter: "DHA1", approverId: "C7937"},
{cNo: "CDH0000404", contractLineItemSelectionChecked: false, companyCode: "1360", profitCenter: "DHA1", approverId: "C7937"},
{cNo: "CDH0000405", contractLineItemSelectionChecked: true, companyCode: "1360", profitCenter: "DHA1", approverId: "C7937"}]
我想要做的是首先检查contractLineItemSelectionChecked状态,如果状态为真需要检查它们是否具有不同的合同ID并且需要将不同的合同ID对象推送到不同的地方
currentState.forEach((el, i) => {
if ( el.contractLineItemSelectionChecked) {
push(currentState[i]);
}
}
我试过这个但没有用
您可以根据需要使用filter
功能
currentState.filter(element => element.status && push(element))
它检查status
是否为真,然后调用push
函数
如果你想创建一个数组,你只能使用所需的对象
const results = currentState.filter(el=> el.contractLineItemSelectionChecked);
此处过滤功能的文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.