Demo: skip
The skip is a filter operator that allows us skip the first N items from source and emit the rest of the items as they arrive.
skip( skipNItems)
//Emits from 0 to 7
const source = timer(500, 1000).pipe(take(8));
//skips 0 , 1 - The first two items
const filterItems = skip(2);
const output = source.pipe(filterItems).subscribe(v=>console.log(v))
What is happening ?
The operators like "take" , "take Last", "skip", "skip Last", "first" and "last"! -- help us filter the source items based on their position.
For instance, the operator "skip":
- allows us skip the first N items from source, before emitting the rest of the items as they arrive.
Coming to our demo, the source is supposed to emit 8 items. - Starting with 0, 1, 2, upto 7.
But, if we do not want the first two items from the source:
- We can pipe our source through skip(2) filter operator.
- This filter will discard the first two items.
- And, start emitting the values from the 3rd item onwards, immediately as they arrive.
- Thus, in the demo it discards 0 & 1, but after that, it keeps emitting the rest of the items.