I know you are supposed to be able to break out of an each statement by returning, which is what I'm trying to do, but I must be doing something wrong and it seems so simple I can't find it.
I have code like this
function create() {
var test = hasThing();
if (test) {
$('#myForm').submit();
} else {
alert('you suck!')
}
}
function hasThing() {
$('.selects').each(function() {
if (this.value != "") {
return true;
}
});
return false;
}
I have set breakpoints on "return true;" and hit it but var test is always false because for some reason the .each() loop continues and the hasThing() function continues. I've tried switching things around so that I return false in the .each() just in case for some reason that mattered but it didn't change anything.
I don't get it. Seems counter to how the documentation says it should work.
.eachyou have to returnfalse, and returning from inside theeachloop does not return from the outer function.Seems counter to how the documentation says it should work.- the documentation says "You can stop the loop from within the callback function by returning false". How is the behavior not inline with the docs?