Merge pull request #1543 from rahuldahal/patch-1
Create removeAllWhitespaces.md
This commit is contained in:
16
snippets/removeWhitespace.md
Normal file
16
snippets/removeWhitespace.md
Normal file
@ -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.'
|
||||
```
|
||||
Reference in New Issue
Block a user