mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 03:34:26 +03:00
761 B
761 B
trimEnd
Removes trailing whitespace or specified characters from a string.
Signature
function trimEnd(str: string, chars?: string | string[]): string;
Parameters
str
(string
): The string from which trailing characters will be trimmed.chars
(string | string[]
): The character(s) to remove from the end of the string.
Returns
(string
): The resulting string after the specified trailing character has been removed.
Examples
const trimmedStr1 = trimEnd('hello---', '-'); // returns 'hello'
const trimmedStr2 = trimEnd('123000', '0'); // returns '123'
const trimmedStr3 = trimEnd('abcabcabc', 'c'); // returns 'abcabcab'
const trimmedStr4 = trimEnd('trimmedxxx', 'x'); // returns 'trimmed'