nth
nth() function
Returns the nth element of the given Iterable/AsyncIterable
Signature:declare function nth(index: number, iterable: readonly []): undefined;
declare function nth<T>(index: number, iterable: Iterable<T>): T | undefined;
declare function nth<T>(index: number, iterable: AsyncIterable<T>): Promise<T | undefined>;
declare function nth<T extends Iterable<unknown> | AsyncIterable<unknown>>(index: number): (iterable: T) => ReturnValueType<T, IterableInfer<T> | undefined>;
Example
nth(2, [1,2,3,4]); // 3
nth(5, [1,2,3,4]); // undefined
nth(2, ['name', 'gender', 'age']); // 'age'
nth(3, ['name', 'gender', 'age']); // undefined
nth(2, 'abcdefg'); // 'c'
nth(10, 'abcdefg'); // undefined