Skip to content

re: How to Trim String in JavaScript VIEW POST


The solution given in the Community Input removes all the whitespace from the string. That isn't trimming exactly. The correct way to do it should be...

let str = "      Samantha Ming      "
let trimmedStr = str.replace(/^\s+ | \s+$/g , '')    

console.log(trimmedStr)     // "Samantha Ming"

OH good call! let me add your point to the code notes! Thanks for info 👏

code of conduct - report abuse