不管在哪种语言中去除字符串首尾空格都是会经常用到的
JavaScript中我们经常用的去除首尾空格方式是替换,比如:
str = ' hello world ' console.log(str.replace(/^\s+|\s+$/g, '')) // hello world而如今ES10将会让我们更加方便的去除空格
console.log(str.trimStart()) console.log(str.trimEnd())

JavaScript此外还提供了str.trimStart()的别名 str.trimLeft()
还有str.trimEnd()的别名 str.trimRight()
评论一下?