javascriptthis contains spaces
を使用すると、どのような機能になり ますか?this contains spaces
同様のSOの質問を使用して、次のことを試しましたが、これを機能させることができませんでした。
var string = " this contains spaces ";
newString = string.replace(/\s+/g,''); // "thiscontainsspaces"
newString = string.replace(/ +/g,''); //"thiscontainsspaces"
これを達成するための単純な純粋なJavaScriptの方法はありますか?