W3cubDocs

/RxJS

pairs

function stable

Convert an object into an Observable of [key, value] pairs.

pairs<T>(obj: Object, scheduler?: SchedulerLike): Observable<[string, T]>

Parameters

obj

Type: Object.

scheduler

Optional. Default is undefined.

Type: SchedulerLike.

Returns

Observable<[string, T]>

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 a javascript object to an Observable

import { pairs } from 'rxjs';

const obj = {
  foo: 42,
  bar: 56,
  baz: 78
};

pairs(obj)
.subscribe(
  value => console.log(value),
  err => {},
  () => console.log('the end!')
);

// Logs:
// ["foo", 42],
// ["bar", 56],
// ["baz", 78],
// "the end!"

@param {Object} obj The object to inspect and turn into an Observable sequence. @param {Scheduler} [scheduler] An optional IScheduler to schedule when resulting Observable will emit values. @returns {(Observable<Array<string|T>>)} An observable sequence of [key, value] pairs from the object.

© 2015–2018 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