I have this nested for-loop that I am having difficulty turning into a one liner. What is the best way to eliminate the nested for? Thanks.
for (const house of this.houses){
for (const room of house.rooms){
this.plans.push(room.layout.id);
}
}
2
Answers
You can try this:
forEach calls a function for each item in an array.
You could map the nested
id
.For better readability: