首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >检查在react js中是否至少有一个条件为真

检查在react js中是否至少有一个条件为真
EN

Stack Overflow用户
提问于 2022-08-07 07:23:30
回答 7查看 240关注 0票数 -1

我有一个对象tableRows数组。

代码语言:javascript
运行
复制
tableRows = [
    {
        purchase_sales:1000,
        yearFirstRemAmount: 1456,
        capitalServicePurchase:123234,
        otherServicePurchase: 12323,
        otherStuffPurchase: 8903,
        capitaStuffPurchase: 1200,
        currentYearServiceSell: 47856,
        currentYearStuffSell: 100000,
        yearLastRemAmount: 20000
    }
    {
        purchase_sales:23430,
        yearFirstRemAmount: 12500,
        capitalServicePurchase: 1000010,
        otherServicePurchase: 12360,
        otherStuffPurchase: 12300,
        capitaStuffPurchase: 12000,
        currentYearServiceSell: 123123,
        currentYearStuffSell: 12111,
        yearLastRemAmount: 13120
    }
]

如何检查每个索引的9个键对值中是否至少有一个大于或等于100000。

以下代码不起作用:

代码语言:javascript
运行
复制
const handleValidation = (index)=>{
    if(tableRows[index].purchase_sales<100000 || tableRows[index].yearFirstRemAmount<100000 || tableRows[index].capitalServicePurchase<100000 || tableRows[index].otherServicePurchase<100000 || tableRows[index].otherStuffPurchase<100000 || tableRows[index].capitaStuffPurchase<100000 || tableRows[index].currentYearServiceSell<100000 || tableRows[index].currentYearStuffSell<100000 || tableRows[index].yearLastRemAmount<100000 ){
                alert("'At least one amount should be greater than or equal to 100000!!!")
            }
}

是否有更好、更简洁的方法来完成这一任务?

EN

Stack Overflow用户

发布于 2022-08-07 07:31:58

代码语言:javascript
运行
复制
const handleValidation = (index)=>{
 
 if (Object.values(tableRows[index]).some(value => value < 100000)) {
    alert("'At least one amount should be greater than or equal to 100000!!!")
  }
}
票数 0
EN
查看全部 7 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73265622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档