title: How to compare a LatLng object with another one which is in an array?
body: <p>I'm a beginner in JavaScript. Recently I'm trying to develop associative applications in Google Map. But I bump into a strange problem.</p>
  
  <p>Please refer to the code below.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src = "http://maps.googleapis.com/maps/api/js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;script&gt;
  
  var buf = []; 
  var pos1  = new google.maps.LatLng(1, 2); buf.push(pos1); 
  var pos2  = new google.maps.LatLng(3, 4); buf.push(pos2); 
  var pos3  = new google.maps.LatLng(5, 6); buf.push(pos3); 
  
  //initialize a new object here
  var pos4  = new google.maps.LatLng(3, 4);
  
  if ( buf.indexOf(pos4) != -1 ) 
      document.write("yes");
  else
      document.write("no");
  
  &lt;/script&gt;
  &lt;body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Because value of <code>pos4</code> is same to <code>pos2</code>, the printed result should be "yes" if the <strong>position does exist</strong> in the array. <em>However it printed "no" on the screen.</em></p>
  
  <p>I 've tried to print out the values from <code>pos4</code> and <code>pos2</code>. I found that <strong>both are the same</strong> and I have no idea why this check failed. <strong>Is there any solution to solve the problem?</strong></p>