Skip to content

Latest commit

 

History

History
74 lines (59 loc) · 2.54 KB

slice.md

File metadata and controls

74 lines (59 loc) · 2.54 KB

Rx.Observable.prototype.slice([begin], [end])

The slice method returns a shallow copy of a portion of an Observable into a new Observable object. Unlike the Array version, this does not support negative numbers for begin or end.

Arguments

  1. [begin]: Any: Zero-based index at which to begin extraction. If omitted, this will default to zero.
  2. [end] Number: Zero-based index at which to end extraction. slice extracts up to but not including end.

Returns

Observable: A shallow copy of a portion of an Observable into a new Observable object.

Example

/* Without an end */
var source = Rx.Observable.of(1,2,3,1,2,3)
  .slice(3);

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

// => Next: 2
// => Next: 3
// => Completed

/* With an end */
var source = Rx.Observable.of(1,2,3,1,2,3)
  .slice(2, 1);

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

// => Next: 3
// => Completed

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: