Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array.prototype.remove = function(from, to) {
- var rest = this.slice((to || from) + 1 || this.length);
- this.length = from < 0 ? this.length + from : from;
- return this.push.apply(this, rest);
- };
- // usage:
- // Remove the second item from the array
- array.remove(1);
- // Remove the second-to-last item from the array
- array.remove(-2);
- // Remove the second and third items from the array
- array.remove(1,2);
- // Remove the last and second-to-last items from the array
- array.remove(-2,-1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement