title: Iterat array in JSON javascript
body: <p>I got this JSON here with arrays.</p>
  
  <pre><code>chapter1 = '[\
  {"name" : "Jeff","text":"Hi this is me.","image":"./images/char2.png","bgimg":"./images/bgimg/background1.jpg"}]';
  
  choose1 = '[{"option1":"Come.","option2":"Everything right.","option3":"You are scared!"}]';
  
  chapter1op1 = '[\
  {"name" : "Marco","text":"Hi Jeff! It is me – Marco!","image":"./images/char2.png","bgimg":" "}]';
  </code></pre>
  
  <p>For example I iterat through it with a counter and display the information in my html.</p>
  
  <pre><code>var mydata = $.parseJSON(chapter1);
  var bg ="url(" + mydata[counter].bgimg + ")";
      $("#main-screen-chapter1").css("background-image", bg);
  </code></pre>
  
  <p>At the end of the chapter1 array i display the choose1 array.</p>
  
  <pre><code>var decisionJson = $.parseJSON(choose1);
  if (counter==mydata.length-1){
  
          $( "body").unbind( "click" );
  
          var op1;
          var op2;
          var op3;
  
          for (var i = 0; i &lt; decisionJson.length; i++) {
  
              op1 = $('&lt;tr/&gt;');
              op2 = $('&lt;tr/&gt;');
              op3 = $('&lt;tr/&gt;');
  
              op1.append("&lt;td&gt;" + decisionJson[i].option1 + "&lt;/td&gt;");
              op2.append("&lt;td&gt;" + decisionJson[i].option2 + "&lt;/td&gt;");
              op3.append("&lt;td&gt;" + decisionJson[i].option3 + "&lt;/td&gt;");
  
              $('#option1').append(op1);
              $('#option2').append(op2);
              $('#option3').append(op3);
  
              $('#option1').show();
              $('#option2').show();
              $('#option3').show();
  
  
          }
  </code></pre>
  
  <p>When I click on option1 i want to load the array chapter1op1 and run the script from the beginning again. 
  I tried to overwrite the variable like this.</p>
  
  <pre><code>$( "#option1" ).click(function() {
   mydata = $.parseJSON(chapter1op1);
  });
  </code></pre>
  
  <p>but it is not working.
  Does somebody has an idea how to achieve this with an example?</p>