I am learning Angular 6 and I am puzzled with constructions like a:
this.contentArray.map((v: string, i: number) => `Content line ${i + 1}`)
or like a:
return this.aService.getItems()
.pipe(map(response => response.data));
I am run through the couples of book like a "The_Complete_Book_on_Angular_6" or "Pro Angular 6" (Adam Freeman) but there are no simple explanations there. Google kept silence about that too. Can someone give the right and good tutorial or may be book (for amateurs) about array.map, array.filter and about .pipe(map(...))?
The first one is simply Array.prototype.map, while the second one is the rxjs
map operator.
In the first case, you take an existing array and apply a function to each of its elements
The map() method creates a new array with the results of calling a provided function on every element in the calling array.
[1, 2, 3, 4].map(x => x + 2) // [3, 4, 5, 6]
while the second case is essentialy the same thing in the world of observables.
Applies a given project function to each value emitted by the source Observable, and emits the resulting values as an Observable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With