1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-24 10:22:23 +00:00
This commit is contained in:
ruanyf 2024-06-08 18:08:04 +08:00
parent 9c0896c683
commit 642a4ab3e7

View File

@ -881,9 +881,7 @@ sentence.at(100) // undefined
## 实例方法toReversed()toSorted()toSpliced()with()
很多数组的传统方法会改变原数组,比如`push()``pop()``shift()``unshift()`等等。数组只要调用了这些方法,它的值就变了。现在有一个[提案](https://github.com/tc39/proposal-change-array-by-copy),允许对数组进行操作时,不改变原数组,而返回一个原数组的拷贝。
这样的方法一共有四个。
很多数组的传统方法会改变原数组,比如`push()``pop()``shift()``unshift()`等等。数组只要调用了这些方法,它的值就变了。[ES2023](https://github.com/tc39/proposal-change-array-by-copy)引入了四个新方法,对数组进行操作时,不改变原数组,而返回一个原数组的拷贝。
- `Array.prototype.toReversed() -> Array`
- `Array.prototype.toSorted(compareFn) -> Array`