1// replaces space with '-'
2str = str.replace(/ /g, "-");
3// or
4str = str.split(' ').join('-');
1let originalText = 'This is my text';
2let dashedText = originalText.replace(/ /g, '-');
1title = title.replace(/\s/g , "-");
2var html = "<div>" + title + "</div>";
3// ...