title: how to add values one by one in an array
body: <p>I want to add 8 values of the clicked buttons in an array.</p>
  
  <p>When a user will press any button the id/value against that button stored in an array but my array only save 1st value in the array at array [0].</p>
  
  <p>How to insert other values in an array?</p>
  
  <p>Here is the code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function reply_click(obj) {
    var id = [obj.id];
    for (i = 0; i &lt;= id; i++) {
      alert(id);
    }
  }
  
  var arr = [id];
  
  alert(arr);
  
  if (id[0] == "1") {
    alert(6666666666);
  }
  
  if (id[0] == "2") {
    id[0] = 1;
    id[1] = 2;
    alert(777777777777);
  }
  
  
  if (id[0] == "3") {
    id[0] = 1;
    id[1] = 2;
    id[2] = 3;
    alert('login');
  }
  
  alert(id);
  
  $(document).on('click', '.btn', function() {
  
    alert($(this).val());
  
    var myvalues = $(this).val();
    alert(myvalues);
  
    var cars = [myvalues, "myvaluesv", "Toyota"];
    alert(cars);
    var x = cars.length;
    alert(x);
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;button id="1" onClick="reply_click(this)"&gt;1&lt;/button&gt;
  &lt;button id="2" onClick="reply_click(this)"&gt;2&lt;/button&gt;
  &lt;button id="3" onClick="reply_click(this)"&gt;3&lt;/button&gt;
  
  &lt;button id="tahira" name="btn" class="btn" value="tahirahassan"&gt;hi tahira&lt;/button&gt;
  &lt;button id="sobia" name="btn" class="btn" value="sobia"&gt;hi sobia&lt;/button&gt;
  &lt;form action="testingjquery.php" method="post"&gt;
    &lt;input type="submit" id="btn1" class="btn111" name="val1" value=" i am tahira" /&gt;
    &lt;input type="submit" id="btn2" class="btn112" name="val1" value="hassan" /&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>