Nest all content into snippets
This commit is contained in:
21
snippets/js/s/remove-whitespace.md
Normal file
21
snippets/js/s/remove-whitespace.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
title: Remove whitespaces
|
||||
type: snippet
|
||||
language: javascript
|
||||
tags: [string,regexp]
|
||||
cover: tropical-bike
|
||||
dateModified: 2020-11-03T21:46:13+02:00
|
||||
---
|
||||
|
||||
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