The take
operator in rxjs
is used to emit only the first n values emitted by an observable. Here's an example of how to use it:
index.tsx295 chars7 lines
In this example, of
is used to create an observable that emits the numbers 1 through 5. The take
operator is then used to take only the first 3 values that are emitted by this observable. Finally, subscribe
is called on the new observable take$
which logs the output to the console.
Alternatively, you can use the take
operator by chaining it onto an observable like so:
index.tsx146 chars3 lines
This does the exact same thing as the previous example, but the operator is chained onto the observable directly.
gistlibby LogSnag