var str=new string(" helloworld ");
console. log(str. replace(/(^\s*)|(\s*$)/g,""));
另外还有去左空格和去右空格
去左空格 str. replace(/(^\s*)/g,"")
去右空格 str. replace(/(\s*$)/g,"")
var str=new string(" helloworld ");
console. log(str. replace(/(^\s*)|(\s*$)/g,""));
另外还有去左空格和去右空格
去左空格 str. replace(/(^\s*)/g,"")
去右空格 str. replace(/(\s*$)/g,"")