> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/prim/str/method/.capitalize.md).

# str.capitalize()

第一個字母大寫，後面都小寫。

[🔰 JS](/web/js.md) ⟩ [Types](/web/js/val/type.md) ⟩ [String](/web/js/val/prim/str.md) ⟩ [methods](/web/js/val/prim/str/method.md)

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

```javascript
// ⭐️ string.capitalize()
//    第一個字母大寫
String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
};
```

{% endtab %}

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

* String ⟩&#x20;
  * [.kebabToCamelCase()](/web/js/val/prim/str/method/.kebabtocamelcase.md)
  * [.toDatasetPropName()](/web/js/val/prim/str/method/.todatasetpropname.md)
    {% endtab %}

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

* [Custom Attributes](/web/browser/dom/type/element/attribute/dataset.md#dataset) - dataset
* [⭐️ Fav](/web/master/fav.md)
  {% endtab %}

{% tab title="🗣 討論" %}

* [How do I make the first letter of a string uppercase in JavaScript?](https://stackoverflow.com/questions/1026069/how-do-i-make-the-first-letter-of-a-string-uppercase-in-javascript)
  {% endtab %}
  {% endtabs %}
