Skip to content

lastIndexOfOrThrow

String.lastIndexOfOrThrow(target, source)

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