[Home] > Snippets  > Languages  > JavaScript  > Strings  >  Trim some character

Trim some character

JavaScript

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

TypeScript

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