title: To append an Key:Value pair to my array element only once!
body: <pre><code>var people =[{title:'Alan', hasChild:true},
              {title:'Alice', hasDetail:true},
              {title:'Amos',},
              {title:'Alonzo'},
              {title:'Brad'},
              {title:'Brent'},    
              {title:'Billy'},    
              {title:'Brenda'},   
              {title:'Callie'},
              {title:'Cassie'},   
              {title:'Chris'}];
  </code></pre>
  
  <p>By default my array does not contain any key,value pair which is <code>header:'A'</code> , <code>header:'B'</code> , `header'C' so on... I add them at run time.</p>
  
  <pre><code>for (i = 0, len = people.length; i &lt; len; i++) {
              var headerValue = people[i].header = people[i].title.charAt(0);
  }
  </code></pre>
  
  <p>By doing this my array has a new key,value pair <code>'Header:'FirstLetter of the title'</code>.</p>
  
  <pre><code>var people =[{title:'Alan', hasChild:true, header:'A'},
                  {title:'Alice', hasDetail:true,header:'A'},
                  {title:'Amos',header:'A'},
                  {title:'Alonzo',header:'A'},
                  {title:'Brad',header:'B'},
                  {title:'Brent',header:'B'}, 
                  {title:'Billy',header:'B'}, 
                  {title:'Brenda',header:'B'},    
                  {title:'Callie',header:'C'},
                  {title:'Cassie',header:'C'},    
                  {title:'Chris',header:'C'}];
  </code></pre>
  
  <p>I don't want to add the header:value to all the elementes, If i add the header:value to the element one whose title starts with 'A', then the rest of the elements whose title start's with A should be ignored. <strong>I want the array in this format.</strong></p>
  
  <pre><code>var people =[{title:'Alan', hasChild:true, header:'A'},
                      {title:'Alice', hasDetail:true,},
                      {title:'Amos'},
                      {title:'Alonzo'},
                      {title:'Brad',header:'B'},
                      {title:'Brent'},    
                      {title:'Billy'},    
                      {title:'Brenda'},   
                      {title:'Callie',header:'C'},
                      {title:'Cassie'},   
                      {title:'Chris'}];
  </code></pre>
  
  <p><strong>My updated code....</strong></p>
  
  <pre><code>    function SortByName(x,y) {        
        return ((x.LastName == y.LastName) ? 0 : ((x.LastName &gt; y.LastName) ? 1 : -1 ));    
      }
  
      function RenderPatientSearchData(PatientSearchResponse){
          var PatientSearchData = JSON.parse(PatientSearchResponse);
          var results = PatientSearchData['PatientSearchResult'];
          results.Patient.sort(SortByName);
          rowData = [];
  
          var prevHeader = '';
          for (i = 0, len = results.Patient.length; i &lt; len; i++) {
              var headerValue = results.Patient[i].header = results.Patient[i].LastName.charAt(0);    
                  if (headerValue !== prevHeader) {      
                      headerValue = results.Patient[i].header = results.Patient[i].LastName.charAt(0);    
               }
              prevHeader = headerValue;
  
  ....... some code... 
  
  }
  </code></pre>