js remove spaces from string more than one 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: javascript remove space from two side of string
const string = " this contains spaces ";
string.replace(/\s{2,}/g, '').trim()