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

# str.capitalize()

[🔰 JS](../../../..) ⟩ [Types](../../../type) ⟩ [String](..) ⟩ [methods]()

{% 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()](.kebabtocamelcase)
  * [.toDatasetPropName()](.todatasetpropname)
{% endtab %}

{% tab title="👥 相關" %}
* [Custom Attributes](../../../../../../browser/dom/type/element/attribute/dataset#dataset) - dataset
* [⭐️ Fav](../../../../../master/fav)
{% 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 %}
