How can I implement a function that does the same thing as ArrayList.remove(o)?
The closest thing I have is
Array.prototype.remove = function(o) {
var index = this.indexOf(o);
if(index == -1) {
return;
}
return this.splice(index, index);
}
However it throws an error on the second line, claiming indexOf(o) doesn’t exist. (cannot find function indexOf())
Array.prototype.indexOfis not supported by IE7 and below. So you would need to shim that method aswell before, like(simplified example).
Furthermore, your call to
.splice()is wrong, second argument is the length of elements you want to remove and it should be1.