# str.removeWhitespaces()

{% tabs %}
{% tab title="💾 程式" %}

```javascript
// 🔸 str.removeWhitespaces()
String.prototype.removeWhitespaces = function() {
    return this.replace(/\s+/g, '');
};
```

💈範例：

```javascript
// multi-line string
let str = `
as     void     async     while
`;

str.removeWhitespaces()    // "asvoidasyncwhile"
```

{% endtab %}

{% tab title="👥 相關" %}

* [str.replacewhitespaces](https://lochiwei.gitbook.io/web/js/val/prim/str/method/str.replacewhitespaces "mention") - replace white-spaces with specific delimiter.
  {% endtab %}

{% tab title="⬇️ 應用" %}

* [no-make-up-exam](https://lochiwei.gitbook.io/web/appendix/gas/projects/no-make-up-exam "mention")
* [class-average](https://lochiwei.gitbook.io/web/appendix/gas/projects/class-average "mention")
  {% endtab %}
  {% endtabs %}
