How can I use promise() in jQuery each

How can I use promise() in jQuery each

I have code below:

function checkboxAssign() {
_locationIds = $( 'input[name=location]'). val();
_zoneIds = $( 'input[name=zone]'). val();
_regionIds = $( 'input[name=region]'). val();
_categoryIds = $( 'input[name=category]'). val();

$( 'input[type=checkbox]'). each( function() {
$( this). attr( 'checked', false);
}). promise(). done( function() {
if ( _locationIds != '') {
locationIds = _locationIds. split( '-');
locationIds. forEach( function( el) {
$( '.search-zone input[type=checkbox]'). each( function() {
var dataType = $( this). attr( 'data-type');
var dataId = $( this). val();
if ( dataType == 'locationId' && el == dataId) {
$( this). attr( 'checked', true);
}
});
});
}
if ( _zoneIds != '') {
zoneIds = _zoneIds. split( '-');
zoneIds. forEach( function( el) {
$( '.search-zone input[type=checkbox]'). each( function() {
var dataType = $( this). attr( 'data-type');
var dataId = $( this). val();
if ( dataType == 'zoneId' && el == dataId) {
$( this). attr( 'checked', true);
}
});
});
}
if ( _regionIds != '') {
regionIds = _regionIds. split( '-');
regionIds. forEach( function( el) {
$( '.search-zone input[type=checkbox]'). each( function() {
var dataType = $( this). attr( 'data-type');
var dataId = $( this). val();
if ( dataType == 'regionId' && el == dataId) {
$( this). attr( 'checked', true);
}
});
});
}
if ( _categoryIds != '') {
categoryIds = _categoryIds. split( '-');
categoryIds. forEach( function( el) {
$( '.search-zone input[type=checkbox]'). each( function() {
var dataType = $( this). attr( 'data-type');
var dataId = $( this). val();
if ( dataType == 'categoryId' && el == dataId) {
console. log( el);
$( this). attr( 'checked', true);
}
});
});
}
});
}

checkboxAssign();


However, all checkbox elements are unchecked.
I would like to unchecked all checkbox and then use jQuery each to check them, but promise() seems don't work here.

Thank you.

Terry