Posted By

svenito on 09/29/09


Tagged

array remove


Versions (?)

Remove items from array


 / Published in: JavaScript
 

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

  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  

You need to login to post a comment.