You can solve this problem by adding a delete function to the prototype array.
Array.prototype.remove = function(elem, all) { for (var i=this.length-1; i>=0; i--) { if (this[i] === elem) { this.splice(i, 1); if(!all) break; } } return this; };
Using:
var myArray = ['A', 'B', 'C', 'D', 'A'] myArray.remove('A'); => ["A", "B", "C", "D"] myArray.remove('A', true); => ["B", "C", "D"]
But be careful, expanding your own prototypes, there may be an anti-pattern!
HaNdTriX Apr 10 '13 at 9:12 2013-04-10 09:12
source share