Deleting all white spaces in a string 1

Deleting all white spaces in a string

.replaceAll(/\s/g,'')

Here is what the above code is Doing:
1. We’re using the replaceAll() method to replace all the spaces in the string with nothing.
2. The replaceAll() method takes two arguments:
a. The first argument is a regular expression.
b. The second argument is the replacement string.
3. The regular expression /\s/g is used to match all the spaces in the string.
4. The replacement string is an empty string.
5. The g flag is used to replace all the spaces in the string.

Similar Posts