title: How to toggle an element in array using JavaScript?
body: <p>Here is my code for javascript for this simple task:</p>
  
  <ol>
  <li><strong>Remove</strong> the element if it exists in an array.<br/> </li>
  <li><p><strong>Add</strong> the element if it is not in an array.</p>
  
  <pre><code>if(_.contains(this.types,type_id)){
      var index = this.types.indexOf(type_id);
      this.types.splice(index,1);
  }
  else{
      this.types.push(type_id);
  }
  </code></pre></li>
  </ol>
  
  <p>Is there a more efficient way to do this?           </p>