Q:

javascript replace all spaces with dashes

title = title.replace(/\s/g , "-");
2
var multiSpacesString="I  have     some big    spaces.";
var singleSpacesString=multiSpacesString.replace(/  +/g, ' ');//"I have some big spaces."
1
let originalText = 'This is my text';
let dashedText = originalText.replace(/ /g, '-');
1
title = title.replace(/\s/g , "-");
var html = "<div>" + title + "</div>";
// ...
0
var replaced = str.replace(/ /g, '_');
0
str = str.replace(/\s/g, "&nbsp;");
0

New to Communities?

Join the community