mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2024-04-21 12:32:22 +00:00
docs(array): add at()
This commit is contained in:
@@ -437,3 +437,16 @@ str.replaceAll(regex, replacer)
|
||||
|
||||
上面例子中,正则表达式有三个组匹配,所以`replacer()`函数的第一个参数`match`是捕捉到的匹配内容(即字符串`123abc456`),后面三个参数`p1`、`p2`、`p3`则依次为三个组匹配。
|
||||
|
||||
## 实例方法:at()
|
||||
|
||||
`at()`方法接受一个整数作为参数,返回参数指定位置的字符,支持负索引(即倒数的位置)。
|
||||
|
||||
```javascript
|
||||
const str = 'hello';
|
||||
str.at[1] // "e"
|
||||
str.at[-1] // "o"
|
||||
```
|
||||
|
||||
如果参数位置超出了字符串范围,`at()`返回`undefined`。
|
||||
|
||||
该方法来自数组添加的`at()`方法,目前还是一个第三阶段的提案,可以参考《数组》一章的介绍。
|
||||
|
||||
Reference in New Issue
Block a user