Level 7
You needs to remove previous push value from array()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello guys, I have multiple checkboxes they return values and stored into array, but i don't know how to prevent duplicating on the same values within. So when first i click on checkbox 1 stored value 1 in array , and od step 2 when i unchecked the same checkbox and checked again it duplicate the value so it is like : 1 1(duplicate).
Here is the code that I'm using:
$(document).ready(function(){ $('.column-id :checkbox').on('click', function() {
if ($(this).is(":checked")) {
var arr = [];
var pom = $(this).attr("id");
arr.push(pom);
}
/*if($(this).not(":checked")){
//console.log(arr);
// var grk = jQuery.inArray( pom , arr );
}*/
/* if ($(this).is(":checked")) {
var dump = $(this).attr("id");
var arr = [];
arr.push(dump);
alert(arr.indexOf(this))x
// var a = arr.indexOf(this);
alert(a)*//*
}*//*else if($(this).not(":checked")){
var exclude = $(this).attr("id");
}*/
for($i = 0;$i<arr.length;$i++){
$(".modal-body").append(arr[$i]);
}
});
console.log(arr);
});
All the best Maja .
Please or to participate in this conversation.