RosettaCodeData/Task/Strip-whitespace-from-a-string-Top-and-tail/JavaScript/strip-whitespace-from-a-string-top-and-tail-1.js
2023-07-01 13:44:08 -04:00

11 lines
504 B
JavaScript

{
let s = " \t String with spaces \t ";
// a future version of ECMAScript will have trimStart(). Some current
// implementations have trimLeft().
console.log("original: '" + s + "'");
console.log("trimmed left: '" + s.replace(/^\s+/,'') + "'");
// a future version of ECMAScript will have trimEnd(). Some current
// implementations have trimRight().
console.log("trimmed right: '" + s.replace(/\s+$/,'') + "'");
console.log("trimmed both: '" + s.trim() + "'");
}