Array.prototype.remove = function (obj) {
for(var i = 0; i < this.length; i++) {
if(this[i] === obj) {
if (i == this.length) {
this[i] = null;
} else {
for(var j = i; j < this.length-1; j++) {
this[j] = this[j+1];
}
delete this[j]; // updated from this[j] = null; still not working.
}
}
}
return this;
};
calling it with:
write("ARRAY TEST = " + [22, 33, 44].remove(33).remove(22));
..it prints:
44,,
Why this 2 commas and how to fix my remove function to remove the commas as well?