使用javascript会this contains spaces
变成什么功能 ?this contains spaces
我使用类似的 SO 问题尝试了以下操作,但无法使其正常工作。
var string = " this contains spaces ";
newString = string.replace(/\s+/g,''); // "thiscontainsspaces"
newString = string.replace(/ +/g,''); //"thiscontainsspaces"
有没有一种简单的纯javascript方法来完成这个?