Skip to content

Latest commit

 

History

History
72 lines (57 loc) · 2.52 KB

elementatordefault.md

File metadata and controls

72 lines (57 loc) · 2.52 KB

Rx.Observable.prototype.elementAtOrDefault(index, [defaultValue])

Returns the element at a specified index in a sequence.

Arguments

  1. index (Number): The zero-based index of the element to retrieve.
  2. [defaultValue = null] (Any): The default value if the index is outside the bounds of the source sequence.

Returns

(Observable): An observable sequence that produces the element at the specified position in the source sequence, or a default value if the index is outside the bounds of the source sequence.

Example

/* Finds an index */
var source = Rx.Observable.fromArray([1,2,3,4])
    .elementAt(1);

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

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

/* Not found */
var source = Rx.Observable.fromArray([1,2,3,4])
    .elementAt(4, 0);

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

// => Next: 0
// => Completed 

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: