title: Storing data with nested .each() function causes to replicate values
body: <p>I've modified a survey-multi-choice plugin from JsPsych, in order to get responses in the form of checkboxes, instead of radio-buttons, since I need to present an image to the user, followed by 4 alternatives, like this:</p>
  
  <p><a href="https://i.stack.imgur.com/QrMIt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QrMIt.png" alt="enter image description here"></a> </p>
  
  <p>Where A, B, C and D are also images, with their respective checkbox below each one. This structure must be presented more than once, like this:</p>
  
  <p><a href="https://i.stack.imgur.com/nAJyi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nAJyi.png" alt="enter image description here"></a></p>
  
  <p>So in this example, the expected output would be:</p>
  
  <pre><code> {"Q0":["Option A","Option B"]} //this is the first "question" displayed 
   {"Q1":["Option B","Option C"]} //second one
   {"Q2":["Option B","Option D"]} //third one
  </code></pre>
  
  <p>But instead I get the first answer replicated for the rest of the questions:</p>
  
  <pre><code> {"Q0":["Option A","Option B"]} //this is the first "question" displayed 
   {"Q1":["Option A","Option B"]} //second one
   {"Q2":["Option A","Option B"]} //third one
  </code></pre>
  
  <p>My code is provided below:</p>
  
  <pre><code> $("div." + plugin_id_name + "-question").each(function(index) {
      var id = "Q" + index;
      var val = [];
      var a = $(".jspsych-survey-multi-choicemrbeta-option");
  
      $("input:checkbox:checked").each(function(){        
         val.push($(this).attr("value"));
       });
  
      var obje = {};
      obje[id] = val;
      $.extend(question_data, obje);
  
    });
  </code></pre>
  
  <p>I've tried tracking down the values generated on each step by printing them on console, so I'm guessing the problem is how I'm implementing those nested loops, thus the name of this question.</p>
  
  <p>I've tried different approaches when implementing this loop, without better results:</p>
  
  <pre><code>for (var j = 0; j &lt; trial.options[index].length; j++) {
    if ($('jspsych-survey-multi-choicemrbeta-response-' + j).is(':checked')) {
      val.push($(this).attr("value"));
    }
  } 
  </code></pre>
  
  <p>A working example of my full code can be found <a href="http://plnkr.co/edit/V7mLY9mov4levVyQZoM3" rel="nofollow noreferrer">here</a>, for you to test it (look for the <code>jspsych-survey-multi-choicemrbeta.js</code> file, from line #141). CSS isn't included so it'll look slightly different. </p>
  
  <p>Please note that the output of this code is a CSV file, and the full set of responses is given on a single cell, since all those questions belongs to the same JsPsych "trial".</p>
  
  <p>Thanks for your help.</p>