title: Javascript for...in loop for objetcs not running on last property
body: <p>this is my first post in stackoverflow.. I am trying to iterate over an object(my implementation is an associative array) which in turn has some properties. Now I wish to construct another array out of it in order to use it as a localsource in jquery autocomplete widget for seach operations. Now the problem is that i am using for in loop to that according to the documenations available... However the output is always one less than the original object. The itearation involving the last element is not performed at all. Below is the sample object that I am using as input.</p>
  
  <pre><code>    SubTeachPair = object{"5CS1":{SubAbbrev:"CA-L",SubCode:"5CS1",SubName:"Computer Architecture",TeacherId:"1",TeacherName:"Ayush Pandey",label:"Computer Architecture",value:"5CS1"},"5CS2":{SubAbbrev:"CA-P",SubCode:"5CS2",SubName:"Computer Engg",TeacherId:"10",TeacherName:"MAyush Pandey",label:"Computer Engg",value:"5CS2"}}
  </code></pre>
  
  <p>It has this kind of elements and is dynamically generated so the property names are variable. The loop construct that I have written is</p>
  
  <pre><code>    var SubSource = [];
                  console.log(SubTeachPair);
                  var count = 0;
  
  
                  for(sub in SubTeachPair){
                      console.log(count);
                      SubSource[count] = {};
                      SubSource[count]['label']=SubTeachPair[sub]['label'];
                      SubSource[count]['value']=SubTeachPair[sub]['value'];    
                      count++;    
                  }
  </code></pre>
  
  <p>However, the result for the given input is only:</p>
  
  <pre><code>object{{ label: "Computer Architecture", value: "5CS1"}}
  </code></pre>
  
  <p>Am I missing something here?</p>
  
  <p>edit-- The function that produces the input object is as follows(It is triggered onclick by the next button).</p>
  
  <pre><code>    $('#' + $(this).attr("id")).autocomplete({
                                             source : 'search',
                                             minLength : 1,
                                             change : function(event, ui) {
                                             if( typeof ui.item != 'undefined') {
                                             SubTeachPair[$(this).attr("id")] = {};
                                             //   console.log(ui.item);
                                             SubTeachPair[$(this).attr("id")]['value'] =  $(this).attr("id");
                                           SubTeachPair[$(this).attr("id")]['label'] = $('label[for="' + this.id + '"]').html();
                                             SubTeachPair[$(this).attr("id")]['SubCode'] = $(this).attr("id");
                                             SubTeachPair[$(this).attr("id")]['SubName'] =$('label[for="' + this.id + '"]').html();
                                             SubTeachPair[$(this).attr("id")]['SubAbbrev'] =$('label[for="' + this.id + '"]').attr('id');
                                             SubTeachPair[$(this).attr("id")]['TeacherId'] = ui.item.id;
                                              SubTeachPair[$(this).attr("id")]['TeacherName'] = ui.item.value;
                                          //  console.log(SubTeachPair);
                                              //window.SubTeachPair = SubTeachPair;
  
                                         }
                                 }
                             });
  </code></pre>
  
  <p>I think I have found the cause of the error -- the object that is the input is actually the out put of another form that uses jquery autocomplete . Now when I enter something in the input and then click on the suggestion, the suggestion is filled in the text input, however if i do not click outside the input text and directly click the button which triggers my script, I get that error. Otherwise its fine. Is there any way to avoid that?</p>