Skip to content

Instantly share code, notes, and snippets.

@danman01
Created April 21, 2014 18:31
Show Gist options
  • Save danman01/11151784 to your computer and use it in GitHub Desktop.
Save danman01/11151784 to your computer and use it in GitHub Desktop.
remove single item from array in javascript
/* Removes first specified item from array, if it exists
Use like: ["55","35"].pull("35")
Handles cases where "35" isn't in the array
Modifies array and returns pulled item
*/
Array.prototype.pull = function(x) {
var index = this.indexOf(x);
var to_return = undefined;
if(index !== -1) {
this.splice(index, 1);
to_return = x;
}
return to_return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment