I’ve created a demo for you, I’ve explained it in the code itself. See if it works for you.
const push_value_of_checker = ['1', '2', '3']; // get the data in an array-- Your logic
$(document).ready(function() {
//loop through all the checkboxes
$('.csdtc_chkbox').each(function(key, value_chekbox) {
let $this = $(this); // current element
// check if the array exists and is not empty
if (typeof push_value_of_checker !== 'undefined' && push_value_of_checker.length > 0) {
let value = $(this).val(); // get value of the current checkbox
//console.log(value);
let include = push_value_of_checker.includes(value); // check if the value exists in the array
if(include === true){ // if yes, check the checkbox
$this.prop('checked', 'checked');
}
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--
1. All checkboxes should have a name, if you're going to save it.
2. Name is an array so that it can store multiple values.
3. Same name inputs should have different values(here just for demo purpose{value2})
3. Id of all the elements should be unique.
-->
<input type="checkbox" value="1" name="xyz[]" class="csdtc_chkbox" id="any-id-1">Value 1
<input type="checkbox" value="2" name="xyz[]" class="csdtc_chkbox" id="any-id-2">Value 2
<input type="checkbox" value="2" name="xyz[]" class="csdtc_chkbox" id="any-id-3">Value 2
<input type="checkbox" value="3" name="xyz[]" class="csdtc_chkbox" id="any-id-4">Value 3
<input type="checkbox" value="4" name="xyz[]" class="csdtc_chkbox" id="any-id-5">Value 4