title: How can I find the index of an object inside a Array using underscore.js?
body: <p>I want to get the index of the given value inside a Array using underscore.js.</p>
  
  <p>Here is my case</p>
  
  <pre><code>var array = [{'id': 1, 'name': 'xxx'},
               {'id': 2, 'name': 'yyy'},
               {'id': 3, 'name': 'zzz'}];
  
  var searchValue = {'id': 1, 'name': 'xxx'};
  </code></pre>
  
  <p>I used the following code,</p>
  
  <pre><code>var index = _.indexOf(array, function(data) { 
                  alert(data.toSource()); //For testing purpose 
                  return data === searchValue; 
              });
  </code></pre>
  
  <p>Also tried this too</p>
  
  <pre><code>var index = _.indexOf(array, {id: searchValue.id});
  </code></pre>
  
  <p>But it <code>returns -1</code> . Since it does not enter into that function. So I didn't get that alert message.</p>
  
  <p>Whats wrong with my code.
  Can anyone help me? </p>