Why is it that I get the proper value of “item” in the first loop, but in the each loop I get undefined? How do I keep the value of the “item”?
Here’s the code:
for (item in products_custom){
console.log(item);
$("input:checked").each(function(){
console.log(item);
});
}
Thanks a lot for your help.
You’re not closing your
eachcall properly, so if that were your real code, it would give a syntax error. It should be:Note we use
varto avoid a global. However, neither of these issues fit with the problem you describe, and it works (jsFiddle) after fixing the syntax errors.