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

Type signature

(xs: any[]) => any

Examples

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

Questions

  • How to get the last element of an array?

TypeScript sourceJavaScript source