Last active
January 5, 2016 12:58
-
-
Save Joopmicroop/75056e047e6862f35183 to your computer and use it in GitHub Desktop.
Array add/remove item reminder
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
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 |
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
// 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