title: IndexOf element in js array using a truth function using underscore or jquery
body: <p>I need basically the same functionality as Underscore's <a href="http://documentcloud.github.com/underscore/#find">find</a> but with the index of the element as a result (and not the element itself).</p>
  
  <p>As far as I know, Underscore's <a href="http://documentcloud.github.com/underscore/#indexOf">indexOf</a> looks for a value and doesn't take a function. Same problem for jQuery's <a href="http://api.jquery.com/jQuery.inArray/">inArray</a> function.</p>
  
  <p>I came up with the following implementation, but I'm not sure it is the most efficient:</p>
  
  <pre><code>function myIndexOf(arr, filter) {
    var index;
    $.each(arr, function (i, elt) { if (filter(elt)) { index=i; return false; } });
    return index;
  }
  </code></pre>