replace   with space javascript in string code example Example: javascript replace spaces with nbsp str = str.replace(/\s/g, " ");