How to GetChecked values and Remove unchecked in array

 

Need to create an array having the value of selected checkbox and remove from the array when unchecked that checkbox.


Answer
 
var values=[];

$(".cbx").change(function(){
    if($(this).is(":checked"))
       values.push($(this).val());
    else{
       var x = values.indexOf($(this).val());
       values.splice(x,1);
    }
    alert(values);
});