UNPKG

631 BJavaScriptView Raw
1/**
2 * Returns the element at a specified index in a sequence or undefined if the index is out of range.
3 * @param {Iterable<T>} source The source sequence.
4 * @param {number} index The zero-based index of the element to retrieve.
5 * @return {T} undefined if the index is outside the bounds of the source sequence; otherwise, the element at the
6 * specified position in the source sequence.
7 */
8export function elementAt(source, index) {
9 let i = index;
10 for (const item of source) {
11 if (i === 0) {
12 return item;
13 }
14 i--;
15 }
16 return undefined;
17}
18
19//# sourceMappingURL=elementat.mjs.map