en
Home About project

Replace multiple spaces in a string to single space with JavaScript

If you need to replace multiple spaces (double spaces) in a string to single space with JavaScript you can use next string method:

  • replace(regexp/substr, newstring)

The replace() method searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring.

To replace multiple spaces to single space using JavaScript see example:

    Text = Text.replace(/ {1,}/g," ");