remove extra space in string js code example
Example 1: 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 2: remove extra space in string js
newString = string.replace(/\s+/g,' ').trim();
Example 3: js remove space before string
var str = " Some text ";
str.trim();
// str = "Some text"