pairs

Convert an object into an observable sequence of [key, value] pairs using an optional Scheduler to enumerate the object.

Arguments

  1. obj (Object): The object to inspect and turn into an Observable sequence.

  2. [scheduler] (Scheduler): Scheduler to run the enumeration of the input sequence on. If not specified, defaults to Rx.Scheduler.currentThread

Returns

(Observable): An observable sequence of [key, value] pairs from the object.

Example

// Using Standard JavaScript
var obj = {
  foo: 42,
  bar: 56,
  baz: 78
};

var source = Rx.Observable.pairs(obj);

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// => Next: ['foo', 42]
// => Next: ['bar', 56]
// => Next: ['baz', 78]
// => Completed

ES6 makes for an even nicer experience such as:

Last updated

Was this helpful?