Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I'm trying to filter my data by multiple values

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading