title: jQuery: checking if value is in array, if so, delete, if not, add
body: <p>I'm trying to check if there's a value in the array already. If the value does not exists in array, then it should be added into the array, if the value already exists, it should be deleted.</p>
  
  <pre><code>var selectArr = [];
  $('.media-search').mouseenter(function(){
      var $this = $(this);
      $this.toggleClass('highlight');
  }).mouseleave(function(){
      var $this = $(this);
      $this.toggleClass('highlight');
  
  }).on('click',function(){
      var dataid = $(this).data('id');
  
      if(selectArry){ // need to somehow check if value (dataid) exists.
      selectArr.push(dataid); // adds the data into the array
      }else{
      // somehow remove the dataid value if exists in array already
      }
  
  
  }); 
  </code></pre>