Search⌘ K
AI Features

Manipulating Data in Flight with map

Explore how to apply the map operator to observables in RxJS to transform data as it flows through streams. Understand synchronous modifications of emitted values using pipe and map, enabling smoother reactive data handling in your applications.

Data manipulation in observables is one of the important tasks of RxJS. Right now, you have a collection of almost-right data that needs just one little tweak for it to be correct.

map operator

Generally speaking, a map function takes two parameters (a collection and another function), applies the function to each item, and returns a new collection containing the results.
A simple implementation looks something like this:

TypeScript 3.3.4
function map(oldArr, someFunc) {
let newArr = [];
for (let i = 0; i < oldArr.length; i++) {
newArr.push(someFunc(oldArr[i]));
}
return newArr;
}

JavaScript provides a built-in map for ...