过滤对象中的多个值 [英] Filter multiple values in object
本文介绍了过滤对象中的多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要按多个值过滤对象.
I need to filter an object by multiple values.
对象示例:
items: [
{
url: "https://...",
id: "1693",
type: "ABC",
currencyCode: "SEK",
longName: "Abc",
name: "ABC",
micCode: "DEF",
listingDate: "2018-05-25T00:00:00+02:00",
subType: "STOCK",
market: {
id: "NOROTC"
},
}
.....
如果我过滤一个值就可以了:
If I filter one value it's fine:
var market = data.filter(item => item.market.id === 'NOROTC');
但是我需要做的是:
var market = data.filter(item => item.market.id === 'NOROTC' && item.market.id === 'NGM');
我在stackoverflow上找到了一些类似的帖子,但是在我看来,它们似乎都不起作用.有什么聪明的方法可以做到这一点吗?我也尝试过_.filter(),但没有成功...
I found some similar posts here on stackoverflow but none of them seems to work in my case. Is there a smart way to do this? I tried _.filter() aswell but to no success...
推荐答案
请检查以下示例:
var items = [{
name: 'Amit',
id: 101
},
{
name: 'Amit',
id: 1011
},
{
name: 'Arthit',
id: 102
},
{
name: 'Misty',
id: 103
},
]
var filteredData = items.filter(item => item.name == 'Amit' || item.name== 'Misty');
console.log(filteredData)
这篇关于过滤对象中的多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文