trim in java script code example
Example 1: js remove space from string
string.split(" ").join("")
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"
Example 4: javascript trim
var str=" I have outer spaces ";
var cleanStr=str.trim();//trim() returns string with outer spaces removed