[英].splice() method not working in Javascript?
Whenever I use the splice
method in Javascript like so: 每当我在Javascript中使用
splice
方法时如此:
Array.prototype.mymethod = function() {
return this[num].splice();
}
It returns an error in my tests saying that splice()
is not a method in Javascript. 它在我的测试中返回一个错误,说
splice()
不是Javascript中的方法。 The test only contains an array consisting of ['a', 'b', 'c']
, however it's not working when the prototype I'm using tries to splice()
the array. 测试只包含一个由
['a', 'b', 'c']
组成的数组,但是当我使用的原型试图splice()
数组时,它不起作用。 Can't seem to figure out what's going on. 似乎无法弄清楚发生了什么。 Thanks.
谢谢。
this.splice()
splices the array this.splice()
拼接数组
this[num].splice()
tries to splice the element at index num which is a string and doesnt have a splice method this[num].splice()
尝试在索引num处拼接元素,这是一个字符串并且没有拼接方法
你在数组的元素上调用splice,而不是在数组本身上调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.