简体   繁体   中英

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(','),
             },

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(','),
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM