Returns the element at a specified index in a sequence.
index
(Number
): The zero-based index of the element to retrieve.[defaultValue = null]
(Any
): The default value if the index is outside the bounds of the source sequence.
(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.
/* 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
File:
Dist:
Prerequisites:
NPM Packages:
NuGet Packages:
Unit Tests: