How to break an functional-style iteration?
<p>I'm experimenting with functional-style Javascript and have encountered an interesting situation. I have a foreach function that takes a collection and function object:</p>

<pre><code>var Utils = {};

// Applies a functor to each item in a collection.
Utils.foreach = function(collection, functor)
{
  for (var i = 0; i &lt; collection.length; i++)
  {
    functor(collection[i]);
  }
};
</code></pre>

<p>This is cool. However now I want to implement another function:    </p>

<pre><code>// Checks if a collection contains an item.
Utils.has = function(collection, item)
{
    Utils.foreach(collection, function(obj) {
        if (item === obj) {
            return true; // How to force a return from the foreach function?
        }
    });
    return false;
};
</code></pre>

<p>As you can see I can't implement the "has" function because my return statement doesn't break the iteration.</p>

<p>Can someone recommend a solution for this problem?</p>
