Skip to content

lastOrThrow

Array.lastOrThrow(array)

Returns the last element of array, or throws an error if the array is empty.

Example

ts
import { Array } from "@monstermann/array";

Array.lastOrThrow([1, 2, 3, 4]); // 4
ts
import { Array } from "@monstermann/array";

pipe([1, 2, 3, 4], Array.lastOrThrow()); // 4