In JavaScript there is join
. For instance:
myString.match(/[A-Za-z-_0-9]/g).join("")
""
is a separator between each element of the array, therefore [1, 2, 3].join("")
gives "123"
. However, you can also simply replace all characters not in your whitelist:
myString.replace(/[^A-Za-z-_0-9]/g, "")
, -, .