Skip to content

lastIndexOfOrThrow

ts
function String.lastIndexOfOrThrow(
    target: string,
    source: string,
): number

Returns the index of the last occurrence of source string in target string, or throws an error if not found.

Example

ts
import { String } from "@monstermann/string";

String.lastIndexOfOrThrow("hello world hello", "hello"); // 12
String.lastIndexOfOrThrow("hello world", "foo"); // throws FnError
ts
import { String } from "@monstermann/string";

pipe("hello world hello", String.lastIndexOfOrThrow("hello")); // 12
pipe("hello world", String.lastIndexOfOrThrow("foo")); // throws FnError