Verify an array of objects based on certain conditions. The array of objects starts off empty.
1. If the array is empty and an action occurs, add an object to the array.
2. If the array already contains an object, check if it already exists. If it does, delete the object from the array. If it doesn't, add it to the array.
I've attempted the following code:
var arr = [];
$(document).ready(function() {
$(".rating").click(function() {
var idx = $(this).closest('td').index();
var userskill = {
tech : $(this).closest('td').siblings('td.tech').text(),
skill : $('#listTable thead th').eq(idx).text(),
rValue : $(this).val()
}
add(userskill);
});
});
function add(userskill) {
var flag = false;
arr.push(userskill);
for(var i in arr){
if((arr[i].tech==userskill.tech)&&&(arr[i].skill==userskill.skill)){
arr.splice(i, 1);
}
}