Filter Multiple Values In Object
I need to filter an object by multiple values. Example of object: items: [ { url: 'https://...', id: '1693', type: 'ABC', currencyCode: 'SEK', longName: 'Abc', name: 'ABC', micCode
Solution 1:
Please check the below example:
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)
Solution 2:
You can have an array of IDs you want to filter and use Array.includes()
to filter array as following:
var items = [
{market: {id: "NOROTC"}},
{market: {id: "NGM"}},
{market: {id: "foo"}},
{market: {id: "bar"}},
]
var searchItems = ["NOROTC","NGM"]
var filteredData = items.filter(item => searchItems.includes(item.market.id))
console.log(filteredData)
Hope this helps.
Post a Comment for "Filter Multiple Values In Object"