Skip to main content

Trim some character

JavaScript version

const trim = (str, char) => str.split(char).filter(Boolean).join();

TypeScript version

const trim = (str: string, char: string): string => str.split(char).filter(Boolean).join();

Examples

trim('/hello world//', '/'); // hello world
trim('"hello world"', '"'); // hello world
trim(' hello world ', ' '); // hello world

Comments