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);
// ... after specific length
const trimString = (string, length = 15)=>(string.slice(0,string.length >= length - 3?length - 3:string.length).padEnd(string.length >= length - 3?length:string.length, '.'))
var str=" I have outer spaces ";
var trimmedStr = str.replace(/s/g, '');
/**
* `" some string with spaces on both ends ".trim()`
* removes whitespace from both ends of a string
* @returns a new string, without modifying the original string
*/
text.trim();