Last active
December 19, 2015 16:29
-
-
Save decnorton/5983922 to your computer and use it in GitHub Desktop.
Adds .remove() method to Array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Array Remove | |
* | |
* Based on code by John Resig http://ejohn.org/blog/javascript-array-remove/ | |
*/ | |
Array.prototype.remove = function(from, to) { | |
// If first arg is not a number, try and find it in the array | |
if(isNaN(from)) { | |
from = this.indexOf(from); | |
if(from < 0) { | |
return; | |
} | |
} | |
var rest = this.slice((to || from) + 1 || this.length); | |
this.length = from < 0 ? this.length + from : from; | |
return this.push.apply(this, rest); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment