title: Trouble using indexOf on a complex array
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8668174/indexof-method-in-an-object-array">indexOf method in an object array?</a>  </p>
  </blockquote>
  
  
  
  <p>I have a javascript array which follows this format:</p>
  
  <pre><code>var arrayName = [
  {id: "a", gender: "man",   item: "stuff"},
  {id: "b", gender: "woman", item: "stuff"},
  {id: "c", gender: "man",   item: "stuff"},
  {id: "d", gender: "man",   item: "stuff"}
  ];
  </code></pre>
  
  <p>Is there a way that I can use array.indexOf to find an index in the array, when for example I know the "id" variable. </p>
  
  <p>For example I tried;</p>
  
  <pre><code>var position = arrayName.indexOf("b");
  arrayName[position].gender = "man"
  </code></pre>
  
  <p>At the moment I am using;</p>
  
  <pre><code>for(var i=0; i&lt;arrayName.length; i++) {
     if(arrayName[i].id == "b"){
         arrayName[i].gender = "man";
     }
  }
  </code></pre>
  
  <p>This second technique works but the actual array I am using has 150 entries and 10 items in each entry so looping through it all seems very wasteful when I know the "id" of the entry I want to edit. indexOf would be a much cleaner approach if I can get it working.</p>