Skip to content

Instantly share code, notes, and snippets.

@juanbrusco
Created August 31, 2018 22:05
Show Gist options
  • Save juanbrusco/f8a4d862ce4483faad2796aa84b493c1 to your computer and use it in GitHub Desktop.
Save juanbrusco/f8a4d862ce4483faad2796aa84b493c1 to your computer and use it in GitHub Desktop.
Add item to array (if exists then remove) - Javascript
this.array = [];
selectCarouselItem(itemToAdd) {
if (this.array.indexOf(itemToAdd) != -1) {
this.array.splice(this.array.indexOf(itemToAdd), 1)
} else {
this.array.push(itemToAdd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment