RxJS how to get specific attribute values from nested array of objects
const obj = {
name: 'campus',
buildings: [
{
name: 'building',
floors: [
{
name: 'floor'
}
]
}
]
};
Is there a way to get names in RxJS. Basically I need output as [campus, building, floor]
Observable.of(obj).map((res) => res.name).subscribe((val) => console.log(val));
I know how to do this without using RxJS. But I would like to know how to do using RxJS. Thanks in advance
Currently I'm doing something like below
const names = [];
names.push(obj.name);
obj.buildings.forEach((building) => {
names.push(building.name);
building.floors.forEach((floor) => {
names.push(floor.name);
});
});
console.log(names);