How to replace all spaces in a string

var result = replaceSpace.replace(/ /g, ";");

Here, / /g is a regex (regular expression). The flag g means global. It causes all matches to be replaced.


Pure Javascript, without regular expression:

var result = replaceSpacesText.split(" ").join("");