Remove items from array


/ Published in: JavaScript
Save to your folder(s)

This extends arrays withe a removeItems operation to remove all occurances of from
usage: myArray.removeItems("words");


Copy this code and paste it in your HTML
  1. Array.prototype.removeItems = function(item) {
  2. var i = 0;
  3. while (i < this.length) {
  4. if (this[i] == item) {
  5. this.splice(i, 1);
  6. } else {
  7. i++;
  8. }
  9. }
  10. return this;
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.