Here is my code for javascript for this simple task:
- Remove the element if it exists in an array.
Add the element if it is not in an array.
if(_.contains(this.types,type_id)){ var index = this.types.indexOf(type_id); this.types.splice(index,1); } else{ this.types.push(type_id); }
Is there a more efficient way to do this?