How to Extract Specific Attribute Values from Nested Objects Array using RxJS
const obj = {
name: 'campus',
buildings: [
{
name: 'building',
floors: [
{
name: 'floor'
}
]
}
]
};
Is it possible to retrieve names in RxJS? Essentially, the desired output is [campus, building, floor]
Observable.of(obj).map((res) => res.name).subscribe((val) => console.log(val));
I am aware of how to achieve this without the use of RxJS. However, I am interested in learning how to accomplish this task using RxJS. Thank you in advance
Currently, my approach looks something like the code snippet 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);