Returns the first element or undefined when there are no elements in the given array.

Type signature

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

Examples

first([1, 2, 3]);
// ⇒ 1
Try in REPL
first([]);
// ⇒ undefined
Try in REPL

Questions

  • How to get the first element of an array?

TypeScript sourceJavaScript source