Home > Net >  I'm trying to filter my data by multiple values
I'm trying to filter my data by multiple values

Time:10-05

fee: "20 TEST"
id: "1.11.506157"
info: "[userlink = newdemo1], send 1 TEST to , [userlink = gs6]"
key: "1.11.506157"
time: "2022-09-12T07:06:36"
type: "transfer"


fee: "5 TEST"
id: "1.11.396766"
info: "[userlink = gs6], upgraded account to lifetime member"
key: "1.11.396766"
time: "2022-08-29T09:00:18"
type: "account_upgrade"

fee: "0.00638 TEST"
id: "1.11.396764"
info: "[userlink = nathan], registered the account , [userlink=gs6]"
key: "1.11.396764"
time: "2022-08-29T08:59:33"
type: "account_create"

this is my data and want to filter it by type .

I'm doing like this...

const filteredData = allData.filter((e) => e.type === 'account_create' && 'transfer' && 'account_update');

but it doesn't return anything.

CodePudding user response:

This will not work, you need to check the type on each one with e.type like

const filteredData = allData.filter((e) => e.type === 'account_create' && e.type === 'transfer' && e.type === 'account_update');

But It would be better to put the types in an array and check with includes.

const types = ['account_create', 'transfer', 'account_update'];
const filteredData = allData.filter((e) => types.includes(e.type));
  • Related