JSFiddle - React, Tailwind, and code Playground
HTML
<input id="chk1" type='checkbox' />
<input id="chk2" type='checkbox' />
<input id="chk3" type='checkbox' />
<input id="chk4" type='checkbox' />
JavaScript
var idArray = $("input").map(function(i,e) { return $(e).prop('id'); });
var idContainerArray = ['chk2','chk3'];
$.each(idArray, function (i, el) {
if ($.inArray(el, idContainerArray) != -1) {
console.log('hi');
$('#'+el).prop("checked", true);
}
});