Advertisement
nmnikolov

09.removeArrayItem.js (Filkolev

Nov 21st, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Array.prototype.removeItem = function () {
  2.     for (var j = 0; j < arguments.length; j++) {
  3.         for (var i = 0; i < this.length; i++) {
  4.             if (this[i] === arguments[j]) {
  5.                 this.splice(i, 1);
  6.             }
  7.         }
  8.     }
  9.    
  10.     return this;
  11. }
  12.  
  13. var arr = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
  14. arr.removeItem(1, 111);
  15. console.log(arr);
  16.  
  17. arr = ['hi', 'bye', 'hello'];
  18. arr.removeItem('bye', 'hi');
  19. console.log(arr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement