Last active
October 16, 2019 06:34
-
-
Save Vincenius/19fa8e9de507c6964971bd91e67d59b4 to your computer and use it in GitHub Desktop.
Toggle array item
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
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