How to return a value from inside an interator in Javascript
<p>I have a function that I want to return true or false.</p>

<p>Inside the function I iterate through some elements on the page and check their values.</p>

<p>But if I put a return statement inside the iterator, it will return from the anonymous function right?  (and not the outer function).</p>

<pre><code>function someElementHasZeroValue() {
  $('.some-class').each(function(){
    if($(this).html() == '0'){
      return true;
    }
  });
  return false;
}
</code></pre>

<p>So this function always returns false no matter what.</p>

<p>What is the best way to do this?  The solution below seems to work but it doesn't seem very elegant.</p>

<pre><code>function someElementHasZeroValue() {
  elements_found_with_zero_value = 0;
  $('.some-class').each(function(){
    if($(this).html() == '0'){
      elements_found_with_zero_value += 1;
    }
  });

  if(elements_found_with_zero_value &gt; 0){
    return true;
  }else {
    return false;
  }
}
</code></pre>

<p>More generally, does anyone know why Javascript requires you to iterate through elements with an anonymous function as opposed to a normal iterator like most languages, or is there some way to do it I'm not aware of?</p>
