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
/**
* `" 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
*/
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
/**
* `" 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
*/