I have a string like this: "22 - 11 - 33".
I would like to remove all the dashes '-' and all the spaces to return a string like this "221133".
I know there is a replace() method but as far as I know it only removes one thing passed into it. I would like to remove more than one character type.
"22 - 11 - 33".replace(/[^0-9]/g, '');
should work
Use Regex replace for that:
console.log(
"22 - 11 - 33".replace(/[^\d]/g, '')
);
[^\d] - replace anything that is not number
\d - matches numbers groups, similar to [0-9]
/g - replace all matches