Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active December 24, 2015 11:59
Show Gist options
  • Select an option

  • Save james2doyle/6794715 to your computer and use it in GitHub Desktop.

Select an option

Save james2doyle/6794715 to your computer and use it in GitHub Desktop.
Array.remove. Remove item from array via index. Array.trim. Delete from index start to end.
// remove item from array via index
Array.prototype.remove = function(index) {
if (this.indexOf(index) !== -1) {
this.splice(index, 1);
}
return this;
};
// remove `from` to `to` items
Array.prototype.trim = 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);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment