I'm trying to get checked checkboxes in an array but I want them to be ordered in the order they are selected.
For example, I have 3 checkboxes—
<label for="check-1">check 1</label>
<input type="checkbox" id="check-1" value="1" name="mycheck[]">
<label for="check-2">check 2</label>
<input type="checkbox" id="check-2" value="2" name="mycheck[]">
<label for="check-3">check 3</label>
<input type="checkbox" id="check-3" value="3" name="mycheck[]">
—and I selected Check 2 then Check 3 then Check 1.
I want result to be in array like this ('2','3','1')
I use this function but it's not get them to order
var list = new Array();
$('input[name="mycheck"]:checked').each(function() {
list.push([$(this).val()]);
});
console.log(list);