js replace space with underscore
snippet in javascript

js replace space with underscore

user1829

var string = "my name";
string = string.replace(/ /g,"_"); //returns my_name

javascript replace all spaces

user4110

var str = 'a b c';
var replaced = str.split(' ').join('_');