javascript数组过滤器的倍数和条件 [英] javascript array filter multiple and condition

查看:74
本文介绍了javascript数组过滤器的倍数和条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何过滤具有多个匹配条件的javascript数组.下面的代码返回所有数据,而不仅仅是2.

How to filter a javascript array with multiple matching conditions. The below code returns all the data, instead of just 2.

代码:

this.entityTypes = codeList.Values.filter(c => c.CodeValue === 'CRD_CRE_INS' || 'CRD_EEA_BRA');

示例JSON数组:-

const codeList.Values = [{
    "CodeValue": "CRD_CRE_INS",
    "CodeValueDisplay": "CRD Credit Institution",
  },
  {
    "CodeValue": "CRD_EEA_BRA",
    "CodeValueDisplay": "EEA Branch",
  },
  {
    "CodeValue": "CRD_NON_EEA_BRA",
    "CodeValueDisplay": "Non-EEA Branch",
  }
] 

推荐答案

表达式'CRD_EEA_BRA'始终为真,您必须将代码更改为:

The expression 'CRD_EEA_BRA' is always true, you have to change the code to:

this.entityTypes = codeList.Values.filter(c => c.CodeValue === 'CRD_CRE_INS' ||  c.CodeValue === 'CRD_EEA_BRA');

这篇关于javascript数组过滤器的倍数和条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆