> For the complete documentation index, see [llms.txt](https://mm.ricky.moe/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mm.ricky.moe/other/zheng-ze/ti-mu/zhuan-huan-wei-tuo-feng-ming-ming-fa.md).

# 转换为驼峰命名法

var s1 = "get-element-by-id"; 给定这样一个连字符串，写一个function转换为驼峰命名法形式的字符串 getElementById

{% tabs %}
{% tab title="First Tab" %}

1. 匹配 ' - '
2. 对后面的首字母大写
   {% endtab %}

{% tab title="Second Tab" %}

```javascript
const f = (str) => {
    return str.replace( /[-\w\]/g, m => m.slice(1).toUpperCase()
}
```

{% endtab %}
{% endtabs %}

`replace` 的语法

```javascript
str.replace(regexp|substr, newSubstr|function)
```

其中`function` 的回调参数有

| `match`       | The matched substring. (Corresponds to $& a`bove.)`                                                                                                                                                                                                                                                                    |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `p1, p2, ...` | The *n*th string found by a parenthesized capture group, provided the first argument to `replace()` was a [`RegExp`](https://devdocs.io/javascript/global_objects/regexp) object. (Corresponds to `$1`, `$2`, etc. above.) For example, if `/(\a+)(\b+)/`, was given, `p1` is the match for `\a+`, and `p2` for `\b+`. |
| `offset`      | The offset of the matched substring within the whole string being examined. (For example, if the whole string was `'abcd'`, and the matched substring was `'bc'`, then this argument will be 1.)                                                                                                                       |
| `string`      | The whole string being examined.                                                                                                                                                                                                                                                                                       |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mm.ricky.moe/other/zheng-ze/ti-mu/zhuan-huan-wei-tuo-feng-ming-ming-fa.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
