logo image

JavaScript program to replace spaces with hyphen in a string

27


Following program shows you how to replace spaces with hyphen in a string. In this program we use .replace to replace spaces with hyphen

var input = "Hello World";
var result = input.replace(" ", "-");
console.log("After replacing input string with - is: " + result);

Output:

After replacing input string with - is: Hello-World