Below is the provided information:
userRoom = ['rm1'];
data = [{
name: 'building 1',
building: [{
room: 'rm1',
name: 'Room 1'
},{
room: 'rm2',
name: 'Room 2'
}]
},{
name: 'building 2',
building: [{
room: 'rm3',
name: 'Room 3'
}]
},{
name: 'building 3',
building: [{
room: 'rm1',
name: 'Room 1'
}]
}]
The objective here is to display the data that includes a building with room1
and apply a filter.
The expected result should look like this:
[{
name: 'building 1',
building: [{
room: 'rm1',
name: 'Room 1'
},{
room: 'rm2',
name: 'Room 2'
}]
},{
name: 'building 3',
building: [{
room: 'rm1',
name: 'Room 1'
}]
}]
I attempted to achieve this by utilizing the following code snippet:
data.map(x => x['building'].filter(y=> userRoom.includes(y.room));
However, I encountered issues with its functionality.