Reputation: 11888
I do receive from a service an Observable<Array<Object>>
I would like to apply a function to each element of the Array and return the result in an Observable. I tried the following but it doesn't seem to work
getFoo() {
let f: Observable<Array<Object>> = serviceCall()
return f.map(res => res.forEach(v => myFunction(v)))
}
Any idea how I could do this ?
Upvotes: 1
Views: 272
Reputation: 657078
forEach
doesn't return a new array, it just executes the code for each item. Use map()
instead:
getFoo() {
let f: Observable<Array<Object>> = serviceCall()
return f.map(res => res.map(v => myFunction(v)))
}
Upvotes: 3