Replies: 1 comment 2 replies
-
I don't think it's likely that a new method that mutates arrays will ever be added, at this point, and since |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
其他地方似乎也有不少讨论如:
https://es.discourse.group/t/array-prototype-remove/760
JavaScript 虽然有一个
Array.prototype.splice
函数可以实现这些功能且更强大,但是它对新手或其他语言转来的人不直观。因此拟提出以下方法:Array.prototype.removeAt
从数组的指定索引值处删除元素,将会改变原始数组。返回是否成功删除的布尔值。
定义
Array.prototype.remove
从数组中删除指定的元素,将会改变原始数组。返回成功删除元素的个数。
注意
定义
Array.prototype.insert
将新元素插入到数组的指定索引处,将会改变原始数组。
注意:
定义
同时,由于现在有一个已经结案了的通过复制更改数组的提案,因此也可以考虑同时添加以下方法,它们将不改变原始数组,而是创建原始数组的浅拷贝,并返回操作后的数组副本。
Beta Was this translation helpful? Give feedback.
All reactions