Imt rying to loop over some JSON data that is returned and if the value returned is each to an html element attr add "checked" to the checkbox however this keep throwing an error.
$('.varUserSettingTable tr').each(function(index, el) {
var $this = $(this);
$.each(curdata.VarUserDetails.VARS, function(index, value) {
if (curdata.VarUserDetails.VARS[index] !== null) {
if ($this.find('.SettingCheckbox').attr('name') === curdata.VarUserDetails.VARS[index].userID) {
$this.find('.SettingCheckbox').prop('checked', true);
}
}
});
});
Its throwing the error "Uncaught TypeError: Cannot read property 'userID' of undefined"
on the if statmenet thats making sure .userID !== null
VarUserDetails: Object
VARS:Array[1024]
[0 … 99]
0:null
1:null
2:Object
userChecked:1
userID:"2"
__proto__:Object
3:Object
userChecked:1
userID:"3"
__proto__:Object
...
...
curdata.VarUserDetails.VARS[index]from within the iterator callback? You can simply usevalueinstead.0:nullandVARS. So perhapsvalue[index][index] !== null)?value !== nullwill not catchundefined.