Let say the variable name is
var name = "Stack overflow is great";
I want to change it to
var name = "Stack-overflow-is-great";
I did this
name.replace(/ /g, '-');
and here is the result
var name = "Stack-overflow-is-great-";
There is an extra dash at the end, how do i prevent from the last dash to appear in my string?
replace(/\s/g, "-")name.trim().replace(/ /g, '-');.