trim() does not work on extra space between characters in javascript 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 trim
var str=" I have outer spaces ";
var cleanStr=str.trim();//trim() returns string with outer spaces removed