我想用简单的函数扩展所有数组的属性(这是我的作业)
Array.prototype.remove=(function(value){
var i;
var cleanedArray = new Array();
for(i= 0;i<this.length;i++)
{
if(value !== this[i])
{
cleanedArray.push(this[i]);
}
}
this.length = cleanedArray.length;
for(i=0;i<this.length;i++)
{
this[i] = cleanedArray[i];
} })();
var simpleArray = new Array(3,5,6,7,8,1,1,1,1,1,1,1);
simpleArray.remove(1); console.log(simpleArray);
但是我在控制台中遇到错误,有人可以帮助我吗?
错误 :
Uncaught TypeError: Property 'remove' of object [object Array] is not a function