[Home] > Snippets  > Languages  > JavaScript  > Strings  >  Remove spaces from a string

Remove spaces from a string

JavaScript

const removeSpaces = (str) => str.replace(/\s/g, '')

TypeScript

const removeSpaces = (str: string): string => str.replace(/\s/g, '')

Examples

removeSpaces('hel lo wor ld') // 'helloworld'