title: Javascript Click() Loop
body: <p>I'm learning Javascript and having trouble.
  My HTML:</p>
  
  <pre><code>&lt;a id="1" class="same" href="1"&gt;click&lt;/a&gt;
  &lt;a id="1" class="same" href="1"&gt;click&lt;/a&gt;
  &lt;a id="2" class="same" href="1"&gt;click&lt;/a&gt;
  &lt;a id="3" class="same" href="1"&gt;click&lt;/a&gt;
  &lt;a id="3" class="same" href="1"&gt;click&lt;/a&gt;
  &lt;a id="4" class="same" href="1"&gt;click&lt;/a&gt;
  </code></pre>
  
  <p>And JS:</p>
  
  <pre><code>var dataall = [];
  var a = document.querySelectorAll('.same');
  for (var i = 0; i &lt; a.length; i++) {
      var id = a[i].id;
      dataall.push(id);
  }
  data = dataall.filter(function(elem, pos) {
      return dataall.indexOf(elem) == pos;
  })
  i = 0;
  Click(data, i);
  
  function Click(data, i) {
      setTimeout(function() {
          document.getElementById(data[i]).click();
          if (i &lt; data.length) {
              i++;
              Click(data, i);
          } else {
              alert('done');
          }
      }, 10000)
  }
  </code></pre>
  
  <p>How to click each one for an id 1 2 3 4, not 1 1 2 3 3 4?
  Thank</p>