jQuery: checking if value is in array, if so, delete, if not, add
Use the inArray
method to look for a value, and the push
and splice
methods to add or remove items:
var idx = $.inArray(dataid, selectArr);
if (idx == -1) {
selectArr.push(dataid);
} else {
selectArr.splice(idx, 1);
}