Trim in Javascript Posted on February 12, 2018 by Chandan Sharma in JavaScript, JQueryTrim in Javascript::function myTrim(x) { return x.replace(/^\s+|\s+$/gm,”);}function myFunction() { var str = myTrim(” Hello World! “); alert(str);}Share this:TwitterFacebook Published by Chandan Sharma View all posts by Chandan Sharma