Your selector is considering all the checkboxes on the page which are checked so the extra values are of some other checkboxes, instead use .map
on input:checkbox:checked[name="lecture"]
$('#separate_course_list').on("change", ":checkbox", function () {
var values = $('input:checkbox:checked[name="lecture"]').map(function () {
return this.value;
}).get(); // ["1", "2", "4"]
$("input[name="comment"]").val(values); //this input saves array
});
4
solved how to remove excess data in javascript array [closed]