js string.replace spaces code example
Example 1: js replace space with underscore
var string = "my name";
string = string.replace(/ /g,"_"); //returns my_name
Example 2: string replace javascript
let re = /apples/gi;
let str = "Apples are round, and apples are juicy.";
let newstr = str.replace(re, "oranges");
console.log(newstr)
output:
"oranges are round, and oranges are juicy."
Example 3: javascript replace spaces with br
str = str.replace(/\s/g, "<br>");