diff --git a/snippets/removeWhitespace.md b/snippets/removeWhitespace.md new file mode 100644 index 000000000..1af98f2be --- /dev/null +++ b/snippets/removeWhitespace.md @@ -0,0 +1,16 @@ +--- +title: removeWhitespace +tags: string,regexp,beginner +--- + +Returns a string with whitespaces removed. + +- Use `String.prototype.replace()` with a regular expression to replace all occurrences of whitespace characters with an empty string. + +```js +const removeWhitespace = str => str.replace(/\s+/g,''); +``` + +```js +removeWhitespace('Lorem ipsum.\n Dolor sit amet. '); // 'Loremipsum.Dolorsitamet.' +```