Your Ad Here

Posted By

wizard04 on 08/13/08


Tagged

javascript array


Versions (?)

Array.prune


 / Published in: JavaScript
 

  1. //removes a section of the array, returning what's left; does not affect the original array
  2. //(essentially the opposite of Array.slice)
  3. //example:
  4. // var x = ['a', 'b', 'c', 'd'];
  5. // var y = x.prune(1,3);
  6. // alert(x); //['a', 'b', 'c', 'd']
  7. // alert(y); //['a', 'd']
  8. //end argument is optional
  9. Array.prototype.prune = function(start, end)
  10. {
  11. var result = this.slice(0, start);
  12. if(!isNaN(end)) result.concat(this.slice(end));
  13. return result;
  14. }

Report this snippet  

You need to login to post a comment.