Array.prototype.removeByValue = function (val) {
for (var i = 0; i < this.length; i++) {
if (this[i] === val) {
this.splice(i, 1);
i--;
}
}
return this;
}
var fruits = ['apple', 'banana', 'carrot', 'orange'];
wordsfruits.removeByValue('banana');
console.log(fruits);
// -> ['apple', 'carrot', 'orange']
Revert edit that changed the behavior of the code; apply standard JavaScript formatting & naming conventions
Leon Adler
- 3.4k
- 1
- 33
- 43