zip
function
stable
Combines multiple Observables to create an Observable whose values are calculated from the values, in order, of each of its input Observables.
zip(...args: unknown[]): Observable<unknown>
Parameters
args | Type: |
Returns
Observable<unknown>
:
Description
If the last parameter is a function, this function is used to compute the created value from the input values. Otherwise, an array of the input values is returned.
Example
Combine age and name from different sources
import { zip, of } from 'rxjs'; import { map } from 'rxjs/operators'; let age$ = of(27, 25, 29); let name$ = of('Foo', 'Bar', 'Beer'); let isDev$ = of(true, true, false); zip(age$, name$, isDev$).pipe( map(([age, name, isDev]) => ({ age, name, isDev })) ) .subscribe(x => console.log(x)); // Outputs // { age: 27, name: 'Foo', isDev: true } // { age: 25, name: 'Bar', isDev: true } // { age: 29, name: 'Beer', isDev: false }
Overloads
zip(sources: any[]): Observable<A>
Parameters
sources | Type: |
Returns
Observable<A>
zip(sources: any[], resultSelector: (...values: A) => R): Observable<R>
Parameters
sources | Type: |
resultSelector | Type: |
Returns
Observable<R>
zip(...sources: any[]): Observable<A>
Parameters
sources | Type: |
Returns
Observable<A>
zip(...sourcesAndResultSelector: [any, (...values: A) => R]): Observable<R>
Parameters
sourcesAndResultSelector | Type: |
Returns
Observable<R>
© 2015–2021 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/index/function/zip