title: how to get index of duplicates in a javascript array?
body: <p>I have a sorted array like this:</p>
  
  <pre><code>var a= [
      {id:"1", name:"A", address:"A"},
      {id:"2", name:"A", address:"B"},
      {id:"3", name:"A", address:"C"},
      {id:"4", name:"B", address:"A"},
      {id:"5", name:"B", address:"B"},
      {id:"6", name:"C", address:"A"},
      {id:"7", name:"C", address:"B"},
      {id:"8", name:"C", address:"C"},..
  </code></pre>
  
  <p>What I want to do is get the index of those duplicated 'names' like</p>
  
  <pre><code>index 0-2 =&gt; "A";
  index 3-4 =&gt; "B";
  index 5-7 =&gt; "C";
  </code></pre>
  
  <p>Or even counting those duplicates will do such as <code>3</code> for A, <code>2</code> for B, <code>3</code> for C.</p>
  
  <pre><code>        var counter = 0;
          var prev = "";
          var next = "";
          var prevLink = a[0].name;
  
          for (var i = 0; i &lt; a.length; i++) { 
  
           if(i &gt;= ssRow.length){
               //do nothing
          }else{        
            next  = a[i+1].name;  
          } 
  
          if(prev== next){
            counter++;
          }else{        
            counter = 0;
            prevLink = a[i].name;      
          }
            //play with counter variable
          }
  </code></pre>
  
  <p>But it's not working as expected. Is there a much better way or efficient way to do it?</p>