我想要检查数组中是否已经有某个值,如果这个值不存在于数组中,则应将其添加到数组中;如果该值已经存在,则应将其从数组中删除。
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
}
});