UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

20 lines (18 loc) 631 B
/** * Returns the element at a specified index in a sequence or undefined if the index is out of range. * @param {Iterable<T>} source The source sequence. * @param {number} index The zero-based index of the element to retrieve. * @return {T} undefined if the index is outside the bounds of the source sequence; otherwise, the element at the * specified position in the source sequence. */ export function elementAt(source, index) { let i = index; for (const item of source) { if (i === 0) { return item; } i--; } return undefined; } //# sourceMappingURL=elementat.mjs.map