Skip to content

Instantly share code, notes, and snippets.

@Joopmicroop
Last active January 5, 2016 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Joopmicroop/75056e047e6862f35183 to your computer and use it in GitHub Desktop.
Save Joopmicroop/75056e047e6862f35183 to your computer and use it in GitHub Desktop.
Array add/remove item reminder
Summary:
--------
add: unshift -> array <- push
remove: shift <- array -> pop
Chart:
------
add remove start end
push X X
pop X X
unshift X X
shift X X
// removes item(s) from the original array
// returns an array of removed item(s)
function removeItem(array, item, itemAmount){
var idx = array.indexOf(item);
if(idx > -1) return array.splice(idx, itemAmount || 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment