gpt4 book ai didi

javascript - 如何比较数组中不同对象的值

转载 作者:行者123 更新时间:2023-12-01 00:03:24 26 4
gpt4 key购买 nike

In the image CDH0000403 object should move to GMV1 and CDH0000405 to 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 状态,如果状态为 true 需要检查它们是否有不同的 合约 id 并且需要推送不同的合约 id 对象不同地方

currentState.forEach((el, i) => {
if ( el.contractLineItemSelectionChecked) {
push(currentState[i]);
}
}

我试过了,但没用

最佳答案

您可以使用过滤功能来满足您的需要

currentState.filter(element => element.status && push(element))

它检查status是否为true,然后调用push函数

如果你想创建一个数组,你只需使用所需的对象

const results = currentState.filter(el=> el.contractLineItemSelectionChecked);

过滤器函数的文档 here

关于javascript - 如何比较数组中不同对象的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60561144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com