how to remove extra spaces in js code example
Example 1: remove spaces in a string js
str.replace(/\s+/g, '')
Example 2: js method string remove extra spaces
const sentence = ' My string with a lot of Whitespace. '.replace(/\s+/g, ' ').trim()
// 'My string with a lot of Whitespace.'
Example 3: remove extra space in string js
newString = string.replace(/\s+/g,' ').trim();
Example 4: javascript remove space from string
const removeSpaces = str => str.replace(/\s/g, '');
// Example
removeSpaces('hel lo wor ld'); // 'helloworld'