Skip to content

Instantly share code, notes, and snippets.

@kokanee
Last active December 11, 2015 02:08
Show Gist options
  • Save kokanee/4528139 to your computer and use it in GitHub Desktop.
Save kokanee/4528139 to your computer and use it in GitHub Desktop.
remove an element from array
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"}
@frentsel
Copy link

frentsel commented Aug 9, 2015

Array.prototype.remove = function(id){
return this.splice(id, 1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment