Presented here is a snippet that I've crafted previously.
Array.prototype.clear = function() {
for (var i = 0, s = this.length; i < s; i++) { this.pop(); }
return this;
};
Array.prototype.removeAll = function(item) {
var result = [];
for (var i = 0, j = 0, s = this.length; i < s; i++) {
if (this[i] != item) { result[j++] = this[i]; }
}
this.clear();
for (var i = 0, s = result.length; i < s;) { this.push(result[i++]); }
};
While it may not be the most sophisticated solution out there, it does get the job done. With this functionality, you have the ability to eliminate specific elements from an array easily. Personally, I find the syntax using 'this' quite appealing as it makes the code look cleaner:
arrayVar.removeAll("");
Compared to something like:
arrayVar = clean(arrayVar);
Regardless, what matters is that this method is effective.