I have a output like below from an observable. I want to transform this output into a string format as for all true records "John~Ford,Fiat". I want to acheive this using RXJS operators. Can someone show me how can i get to this.
[{
"name":"John",
"age":30,
"selected" : true,
"cars": [
{ "selected":"true", "name":"Ford", "models": "Mustang"},
{ "selected":"false", "name":"BMW", "models": "320" },
{ "selected":"true", "name":"Fiat", "models":"500" }
]
},
{
"name":"alex",
"age":40,
"selected" : false
"cars": [
{ "selected":"true", "name":"tesla", "models": "x"},
{ "selected":"false", "name":"merc", "models": "300" },
{ "selected":"true", "name":"honda", "models":"accord" }
]
}
]
I am able to filter the records but not sure how to format the to the string output("John~Ford,Fiat".)
myComp.myService.carOptions$.pipe(
take(1),
flatMap(carOptions => carOptions as options[]),
filter(carOption => carOption.selected === true),
flatMap(options => options.values as values[]),
filter(optionValue => optionValue.isSelected === true),
toArray()
);
filteroperator you're using is for filtering out observable results, not for filtering within the results themselves."selected" : false?