I\'m learning RxJS by reading this tutorial http://reactive-extensions.github.io/learnrx/
.
I have a hard time understanding the map method of Obse
Map in Rxjs used for projection, means you can transform the array in to entirely new array. In order to understand how Map works , we can implement our own map function using plain javascript.
Array.prototype.map = function(projectionFunction){
var results=[];
this.forEach(function(item) {
results.push(projectionFunction(item));
});
return results;
};
You can see I have written a map function which accepts an anonymous function as a parameter. This will be your function to apply the projection to transform the array. Inside the map function you can see iterating each item in a array , call the project function by passing each item and finally the result of the projection function will push to the results array.
JSON.stringify([1,2,3].map(function(x){return x+1;}))
Output
[2,3,4]