javascript replace all spaces

JavaScript
var string = "my name";
string = string.replace(/ /g,"_"); //returns my_nameconst name = 'Hi my name is Flavio'
name.replace(/\s/g, '') //HimynameisFlavio
var replaced = str.replace(/ /g, '_');var str = 'a b c';
var replaced = str.split(' ').join('_');
Source

Also in JavaScript: