string replace dash and space with no space js code example
Example 1: javascript replace spaces with dashes
title = title.replace(/\s/g , "-");
Example 2: javascript replace all spaces with dashes
let originalText = 'This is my text';
let dashedText = originalText.replace(/ /g, '-');