title: Generating an array from selected radio buttons in Javascript?
body: <p>I'm generating some radio buttons dynamically. The end result looks like this:</p>
  <pre><code>&lt;div&gt;Question 1:&lt;/div&gt;
  &lt;input type=&quot;radio&quot; name=&quot;1&quot; value=&quot;1&quot;&gt;Yes
  &lt;input type=&quot;radio&quot; name=&quot;1&quot; value=&quot;0&quot;&gt;No
  
  &lt;div&gt;Question 2:&lt;/div&gt;
  &lt;input type=&quot;radio&quot; name=&quot;2&quot; value=&quot;1&quot;&gt;Yes
  &lt;input type=&quot;radio&quot; name=&quot;2&quot; value=&quot;0&quot;&gt;No
  
  &lt;div&gt;Question 3:&lt;/div&gt;
  &lt;input type=&quot;radio&quot; name=&quot;3&quot; value=&quot;1&quot;&gt;Yes
  &lt;input type=&quot;radio&quot; name=&quot;3&quot; value=&quot;0&quot;&gt;No
  </code></pre>
  <p>I need to create an Array from the selected radio buttons that looks like this:</p>
  <pre><code>&quot;someName&quot;: {
          &quot;1&quot;: &quot;1&quot;,
          &quot;2&quot;: &quot;0&quot;
      }
  </code></pre>
  <p>I tried the following but the created array is not what I want:</p>
  <pre><code>let names = [&quot;1&quot;,&quot;2&quot;,&quot;3&quot;]
  let results = [];
  
  document.querySelector(&quot;button&quot;).addEventListener(&quot;click&quot;, function(event){
    results = names.map(function(el){
      return document.querySelector(&quot;input[name='&quot; + el + &quot;']:checked&quot;).value;
    });
    
    console.log(results);
  });
  </code></pre>
  <p>This will create an array like this:</p>
  <pre><code>[
    &quot;1&quot;,
    &quot;2&quot;,
    &quot;3&quot;
  ]
  </code></pre>
  <p>How can I achieve the array I want?</p>