Files
30-seconds-of-code/snippets/removeWhitespace.md
Isabelle Viktoria Maciohsek 81e37d20c0 Consistent whitespace
2020-11-03 21:46:13 +02:00

403 B

title, tags
title tags
removeWhitespace 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.
const removeWhitespace = str => str.replace(/\s+/g, '');
removeWhitespace('Lorem ipsum.\n Dolor sit amet. ');
// 'Loremipsum.Dolorsitamet.'