pairs
function
deprecated
Convert an object into an Observable of [key, value]
pairs.
Deprecation Notes
Use from(Object.entries(obj))
instead. Will be removed in v8.
pairs(obj: any, scheduler?: SchedulerLike)
Deprecation Notes
Use from(Object.entries(obj))
instead. Will be removed in v8.
Parameters
obj | The object to inspect and turn into an Observable sequence. |
scheduler | Optional. Default is An optional IScheduler to schedule when resulting Observable will emit values. |
Description
Turn entries of an object into a stream.
pairs
takes an arbitrary object and returns an Observable that emits arrays. Each emitted array has exactly two elements - the first is a key from the object and the second is a value corresponding to that key. Keys are extracted from an object via Object.keys
function, which means that they will be only enumerable keys that are present on an object directly - not ones inherited via prototype chain.
By default these arrays are emitted synchronously. To change that you can pass a SchedulerLike
as a second argument to pairs
.
Example
Converts an object to an Observable
import { pairs } from 'rxjs'; const obj = { foo: 42, bar: 56, baz: 78 }; pairs(obj).subscribe({ next: value => console.log(value), complete: () => console.log('Complete!') }); // Logs: // ["foo", 42], // ["bar", 56], // ["baz", 78], // "Complete!"
Object.entries required
In IE, you will need to polyfill Object.entries
in order to use this. MDN has a polyfill here
Overloads
pairs(arr: readonly T[], scheduler?: SchedulerLike): Observable<[string, T]>
Deprecation Notes
Use from(Object.entries(obj))
instead. Will be removed in v8.
Parameters
arr | Type: |
scheduler | Optional. Default is Type: |
Returns
Observable<[string, T]>
pairs(obj: O, scheduler?: SchedulerLike): Observable<[keyof O, O[keyof O]]>
Deprecation Notes
Use from(Object.entries(obj))
instead. Will be removed in v8.
Parameters
obj | Type: |
scheduler | Optional. Default is Type: |
Returns
Observable<[keyof O, O[keyof O]]>
pairs(iterable: Iterable<T>, scheduler?: SchedulerLike): Observable<[string, T]>
Deprecation Notes
Use from(Object.entries(obj))
instead. Will be removed in v8.
Parameters
iterable | Type: |
scheduler | Optional. Default is Type: |
Returns
Observable<[string, T]>
pairs(n: number | bigint | boolean | symbol | ((...args: any[]) => any), scheduler?: SchedulerLike): Observable<[never, never]>
Deprecation Notes
Use from(Object.entries(obj))
instead. Will be removed in v8.
Parameters
n | Type: |
scheduler | Optional. Default is Type: |
Returns
Observable<[never, never]>
© 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/pairs