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