Skip to content
Advertisement

How to filter the data from the list and remove the existing room from the data in angular

JavaScript

What I’m trying to do here is to filter the data from the roomList and remove the item from data when they are the same ids.

the expected output should be like this:

JavaScript

I tried to use a filter and map.

JavaScript

Advertisement

Answer

Probably best to first reduce() the room IDs to a Set and then filter() based on that:

JavaScript

Complete snippet:

JavaScript

Alternatively, if you really want to do it in a one-liner and performance is not that big of an issue, you can use some():

JavaScript

Complete snippet:

JavaScript
Advertisement