Files
30-seconds-of-code/snippets/removeWhitespace.md
Isabelle Viktoria Maciohsek 5cb69e3c5c Update snippet descriptions
2020-10-22 20:24:30 +03:00

18 lines
402 B
Markdown

---
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.'
```