title: How to write for loop inside variable in Javascript or is there an alternative solution?
body: <pre><code>$.noConflict(); 
    jQuery(document).ready(function($){
  
  var queuesArr = new Array();
  var i;
  
  for (i = 0; i &lt; document.getElementById('qbeansLength').value; i++){
      queuesArr[i] = document.getElementById('queueID'+i).value}
  
  var data = [
      {
          label: ' Queues',
          children: [
  //I need to write the for loop here and make it like this {label: queuesArr[i] } but it is a variable
              { label: document.getElementById('queueID1').value },
              { label: queuesArr[2] }
  
          ]
      },
      {
          label: 'node2',
          children: [
              { label: 'child3' }
          ]
      }
  ];
  
  $(function() {
      $('#tree1').tree({
          data: data
      });
  });
  
  
  });
  </code></pre>
  
  <p>Hi, everyone. I am a total newbie in javascript. I need to print a tree on a web page. I use <a href="http://mbraak.github.io/jqTree/#introduction" rel="nofollow">this widget</a> for it. I need to write the for loop inside a variable but it is a variable so I think it is impossible. Please help me, is there a solution to my problem? The thing is that I dynamically get elements from another jsp page so the amount of children vary as well as the amount of array elements.</p>