🎯 Returns the last element of the array.

Syntax

TypeScript
import { last } from '@opentf/std';

last<T>(arr: T[] = []): T | undefined

Parameters

  • arr: The source array.

Returns

The last element, or undefined if the array is empty.

Examples

TypeScript
last([1, 2, 3]) //=> 3

last(['a', 'b', 'c']) //=> 'c'

last([]) //=> undefined

last() //=> undefined
Last updated on
Edit this page