title: Store multiple radio button values in an array Javascript
body: <p>I would like to store my test answers in an array in javascript. I created 50 questions with for loop, the user can choose between 4 radio buttons(answer). How could i store these answers in an array?</p>
  <p>MY QUESTION CARDS</p>
  <pre><code>&lt;% for(var i = 0; i &lt; test.questions.length; i++){%&gt;
    &lt;br&gt;
      &lt;div class=&quot;card&quot;&gt;
        &lt;div class=&quot;card-header&quot;&gt;
          &lt;%= test.questions[i].question%&gt;&lt;/h5&gt;
        &lt;/div&gt;
        &lt;ul class=&quot;list-group list-group-flush&quot; style=&quot;padding: 10px;&quot;&gt;
            &lt;li class=&quot;list-group-item&quot;&gt;&lt;input type=&quot;radio&quot; name=&quot;one+&lt;%=i%&gt;&quot; value=&quot;a&quot;&gt; &lt;%= test.answers[0].answer%&gt;&lt;/li&gt;
            &lt;li class=&quot;list-group-item&quot;&gt;&lt;input type=&quot;radio&quot;  name=&quot;one+&lt;%=i%&gt;&quot; value=&quot;b&quot;&gt; &lt;%= test.answers[1].answer%&gt;&lt;/li&gt;
            &lt;li class=&quot;list-group-item&quot;&gt; &lt;input type=&quot;radio&quot; name=&quot;one+&lt;%=i%&gt;&quot; value=&quot;c&quot;&gt; &lt;%= test.answers[2].answer%&gt;&lt;/li&gt;
            &lt;li class=&quot;list-group-item&quot;&gt;&lt;input type=&quot;radio&quot; name=&quot;one+&lt;%=i%&gt;&quot; value=&quot;d&quot;&gt; &lt;%= test.answers[3].answer%&gt;&lt;/li&gt;
            &lt;li class=&quot;list-group-item&quot;&gt;&lt;input type=&quot;radio&quot; name=&quot;one+&lt;%=i%&gt;&quot; value=&quot;e&quot;&gt; &lt;%= test.answers[4].answer%&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;%}%&gt;
  </code></pre>
  <p>WHAT I TRIED:</p>
  <pre><code>
  &lt;script&gt;
    var arr = []
    document.getElementById(&quot;confirm&quot;).addEventListener(&quot;click&quot;, function() {
        for (let index = 0; index &lt; 51; index++) {
        
        var buttonName = &quot;one&quot; + index
       
        var buttChecked = document.querySelector('[name=buttonName]:checked')
        
        if (buttChecked != null) {
          arr.push(buttChecked.value)
        }
        console.log(arr)
      }
    })
  
  &lt;/script&gt;
  </code></pre>