var str=" I have outer spaces ";
var trimmedStr = str.replace(/s/g, '');
var str=" I have outer spaces ";
var cleanStr=str.trim(); //return:"I have outer spaces" >> outer spaces removed
let text = " Hello World! "; // output : Hello World!
let result = text.trim();
//Remove spaces with replace() using a regular expression:
let text = " Hello World! ";
let result = text.replace(/^s+|s+$/gm,''); // output : Hello World!
const arr = [' a ', ' b ', ' c '];
const results = arr.map(element => {
return element.trim();
});
console.log(results);
//result
//['a', 'b', 'c']
//trim single string
var str=" abc c a "
str.trim()
console.log(str);
//result
//abc c a
const string = " H ell o world "
const modified = string.trim()
console.log(string)
// H ell o world
console.log(modified)
// H ell o world
var str=" I have outer spaces ";
var trimmedStr = str.replace(/s/g, '');
var str = ' foo ';
str.trim(); //return string 'foo'
var str = 'foo ';
str.trim(); // return string 'foo'
" Hello World ".trim(); //Hello World
var string = "this is a string";
var length = 7;
var trimmedString = string.substring(0, length);
var str=" I have outer spaces ";
var trimmedStr = str.replace(/s/g, '');
text.trim();