title: Accessing SharePoint list with JavaScript Variable Storage
body: <p>i started yesterday with javascript and i'm trying to get some information from a sharepoint 2010 list and i want print it into a table.
  the following code is in the body tag:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      ExecuteOrDelayUntilScriptLoaded(mainFunction, "sp.js");
      var typeNumber = "1520";
      var statusArray = new Array(3);
      try {
          function mainFunction() {
              var clientContext = new SP.ClientContext.get_current();
              var oList = clientContext.get_web().get_lists().getByTitle('Projektstatus');
  
              //empty Query string cause there are some problems with a lookup field
              var emptyCamlQuery = new SP.CamlQuery();
  
              this.collListItem = oList.getItems(emptyCamlQuery);
              clientContext.load(collListItem);
              clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
              document.write(statusArray[2]);
          }
  
          function onQuerySucceeded(sender, args) {
              var listItemInfo = '';
              var i = 0;
              var listItemEnumerator = collListItem.getEnumerator();
              while (listItemEnumerator.moveNext()) {
                  var oListItem = listItemEnumerator.get_current();
                  if (oListItem.get_item('Title').match(typeNumber)) {
                      statusArray[i] = oListItem.get_item('KPI_Status');
  
                      //Works fine
                      alert("nummer:" + i + statusArray[i]);
  
                      i++;
                  }
              }
          }
          function onQueryFailed(sender, args) {
              alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
          }
  
          var tableOutput = "&lt;table&gt;&lt;tr&gt;&lt;th&gt;Indikatortyp&lt;/th&gt;&lt;th&gt;KPI-Status&lt;/th&gt;&lt;/tr&gt;" +
                          "&lt;tr&gt;&lt;td&gt;Kosten&lt;/td&gt;&lt;td&gt;" + statusArray[2] + "&lt;/td&gt;&lt;/tr&gt;" +
                          "&lt;tr&gt;&lt;td&gt;Technik&lt;/td&gt;&lt;td&gt;" + statusArray[1] + "&lt;/td&gt;&lt;/tr&gt;" +
                          "&lt;tr&gt;&lt;td&gt;Termin&lt;/td&gt;&lt;td&gt;" + statusArray[0] + "&lt;/td&gt;&lt;/tr&gt;" +
                      "&lt;/table&gt;"
          document.write(tableOutput);
      } catch (e) {
          alert(e);
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>the output with the alert works fine but when i want to print the statusArray in the table this doesn't work cause the variable is undefined. i think the problem could be something with createDelegate().</p>