> 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/.todatasetpropname.md).

# str.toDatasetPropName()

convert (kebab-cased) "data-xxx" attribute name to (camel-cased) \`dataset\` property name.

{% tabs %}
{% tab title="string.toDatasetPropName()" %}

```javascript
// ⭐️ string.toDatasetPropName()
//    string is assumed to be in "data-xxx" format (kebab case)
String.prototype.toDatasetPropName = function(){                     
  return this                       // 'data-xx-yy-zz'
    .split('-')                     // ['data', 'xx', 'yy', 'zz']
    .slice(1)                       // remove 'data'
    .map((str, i) => (i === 0 ? str : str.capitalize()) ) // ['xx', 'Yy', 'Zz']
    .join('');                      // xxYyZz
};
```

{% endtab %}

{% tab title="⬆️ 需要" %}

* String ⟩ [.capitalize()](/web/js/val/prim/str/method/.capitalize.md)
  {% endtab %}
  {% endtabs %}
