Last active
December 11, 2015 02:08
-
-
Save kokanee/4528139 to your computer and use it in GitHub Desktop.
remove an element from array
This file contains 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.prototype.remove = function(idx){ | |
var temp = new Array(); | |
var i = this.length; | |
while(i > idx){ | |
var kk = this.pop(); | |
temp.push(kk); | |
i--; | |
} | |
for(var i=temp.length - 2; i>=0; i--){ | |
this.push(temp[i]); | |
} | |
} | |
// usage | |
var tArray = {"a", "b", "c"}; | |
tArray.remove(2); | |
// result {"a","b"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Array.prototype.remove = function(id){
return this.splice(id, 1);
}