Files
30-seconds-of-code/snippets/remove-whitespace.md
2023-04-28 22:29:23 +03:00

473 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Remove whitespaces snippet
string
regexp
tropical-bike 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.
const removeWhitespace = str => str.replace(/\s+/g, '');
removeWhitespace('Lorem ipsum.\n Dolor sit amet. ');
// 'Loremipsum.Dolorsitamet.'