How can I selectively return only a specific part of the matched object while using the filter method on a list?
For example:
let comments = [{
"postId": 6,
"status": "ACTIVE",
"id": 28,
"name": "quo voluptates voluptas nisi veritatis dignissimos dolores ut officiis",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e6b48988889fa69489958f8887c8899481">[email protected]</a>",
"body": "voluptatem repellendus quo alias at laudantium\nmollitia quidem esse\ntemporibus consequuntur vitae rerum illum\nid corporis sit id"
},
{
"postId": 6,
"id": 29,
"status": "INACTIVE",
"name": "eum distinctio amet dolor",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a406f646463646d79555a657f78665794a6f7863696b24686370">[email protected]</a>",
"body": "tempora voluptatem est\nmagnam distinctio autem est dolorem\net ipsa molestiae odit rerum itaque corporis nihil nam\neaque rerum error"
}
];
comments.filter((ob, i) => {
return ob.status == "ACTIVE" && ob.id
})
In this scenario, the filter function applied to comments
returns the matching object. However, my goal is to retrieve only a list of id
.