Returns the second element or undefined when there are less than two elements in the given array.

Type signature

<T>(xs: T[]) => T | undefined

Examples

second([1, 2, 3, 4, 5]);
// ⇒ 2
Try in REPL
second([1]);
// ⇒ undefined
Try in REPL
second([]);
// ⇒ undefined
Try in REPL

Questions

  • How to get the second element of an array?

TypeScript sourceJavaScript source