seanberlin
seanberlin

Reputation: 171

How to filter mapped array items within a object?

I have a table, which displays a list of Approved Attachments along with their document type in a table section called 'Attachments'. Which is part of a much larger tableData object.

These attachments have a property of `'isApproved' (along with .name & .typeName), I only want to display the properties where this is true, however I'm not sure how to filter the below code to say 'where x.isApproved === true' for example.

attachments: {
              name: data.attachments.map((x) => x.name).join(','),
              documentGroup: data.attachments.map((x) => x.typeName).join(','),
             },

Upvotes: 0

Views: 32

Answers (1)

Kinglish
Kinglish

Reputation: 23654

Adding a filter in the beginning of the chain should do the trick

attachments: {
  name: data.attachments.filter(x => x.isApproved).map((x) => x.name).join(','),
  documentGroup: data.attachments.filter(x => x.isApproved).map((x) => x.typeName).join(','),
},

Upvotes: 1

Related Questions