{% hint style="info" %}
New to transformation operators? Check out the article Get started transforming streams with map, pluck, and mapTo!
{% endhint %}
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+
import { from } from 'rxjs';
import { map } from 'rxjs/operators';
//emit (1,2,3,4,5)
const source = from([1, 2, 3, 4, 5]);
//add 10 to each value
const example = source.pipe(map(val => val + 10));
//output: 11,12,13,14,15
const subscribe = example.subscribe(val => console.log(val));
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+
import { from } from 'rxjs';
import { map } from 'rxjs/operators';
//emit ({name: 'Joe', age: 30}, {name: 'Frank', age: 20},{name: 'Ryan', age: 50})
const source = from([
{ name: 'Joe', age: 30 },
{ name: 'Frank', age: 20 },
{ name: 'Ryan', age: 50 }
]);
//grab each persons name, could also use pluck for this scenario
const example = source.pipe(map(({ name }) => name));
//output: "Joe","Frank","Ryan"
const subscribe = example.subscribe(val => console.log(val));
- Alphabet Invasion Game
- Battleship Game
- Catch The Dot Game
- Game Loop
- HTTP Polling
- Lockscreen
- Memory Game
- Mine Sweeper Game
- Save Indicator
- Smart Counter
- Space Invaders Game
- Stop Watch
- Swipe To Refresh
- Tetris Game
- Type Ahead
- map 📰 - Official docs
- map - In Depth Dev Reference
- map vs flatMap 🎥 - Ben Lesh
- Transformation operator: map and mapTo 🎥 💵 - André Staltz
- Build your own map operator 🎥 - Kwinten Pisman
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/map.ts