How would I remove blank characters from a string in JavaScript?
A trim is very easy, but I don’t know how to remove them from inside the string. For example:
222 334 -> 222334
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Nick Craver has a good response, if you’re OK with regex, go for it.
I just want to add that you can do this without Regex as well. You can just use a normal JavaScript replace(), using the parameters (” “, “”) to replace all whitespace with empty strings.
Update: Whoops, this won’t work with multiple whitespaces.
JavaScript replace method on w3schools.