Skip to content

Instantly share code, notes, and snippets.

@Vincenius
Last active October 16, 2019 06:34
Show Gist options
  • Save Vincenius/19fa8e9de507c6964971bd91e67d59b4 to your computer and use it in GitHub Desktop.
Save Vincenius/19fa8e9de507c6964971bd91e67d59b4 to your computer and use it in GitHub Desktop.
Toggle array item
function toggleArrayItem(arr, item) {
arr.includes(item)
? arr.filter(i => i !== item) // remove item
: [ ...arr, item ]; // add item
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment