title: Passing an array to a JSON object for Jade rendering
body: <p>I have a node.js server written in express and at a certain moment I send to some .jade page an array. The problem is that when rendering the Jade page, the Jade compiler renders the array as <code>[object Object]</code> and the JavaScript compiler on Chrome complains about it saying "Unexpected identifier".</p>
  
  <p>This is the Jade code:</p>
  
  <pre><code>!!! 5
  html(lang="en")
      head
      title= "Rankings"
  
      body
          h1 Ranking
  
          div(id="rankings")
  
      script(type='text/javascript')
  
          function fillRanking(){
              var rankArray = #{ranking};
              alert("inside fillranking");
              var divElement = document.getElementById("rankings");
              for(var i = 0; i&lt; rankArray.length; i++){
                  divElements.innerHTML += "" + i+1 + ". " + rankArray[i].Username + " " + rankArray[i].Points;
              }
          }
  
          fillRanking();
  </code></pre>
  
  <p>As you can see it's really simple, I just fill a div with the info given by what's inside the <code>#{ranking}</code> variable passed by node.js to Jade. The alert on the second line doesn't fire because the Unexpected Identifier error happens as soon as I try to assign the <code>#{ranking}</code> variable.</p>
  
  <p>The following is the code in my node.js with express</p>
  
  <pre><code>app.get('/ranking', function (req, res) {
      //get the first ten people in the ranking
      var firstTen = getRanking(10, function(results){
          //compute the array of results
          var result = {
              ranking: [],
          }
          for(var i = 0; i &lt; results.length; i++){
              result.ranking[i] = results[i];
          }
          //render the ranking with all the info
          console.log(result);
          res.render(__dirname + '/pages/ranking/ranking.jade', {
              ranking: result,
          });
      });
  });
  </code></pre>
  
  <p>I create an object with inside an array of results, I put the results I found out of the query inside it and I pass it to the rendering engine. The <code>console.log(results)</code> call prints the <code>result</code> object correctly, for example like this:</p>
  
  <pre><code>{ ranking: 
     [ { Username: 'usr1',
         _id: 4ed27319c1d767f70e000002,
         Points: 100 },
       { Username: 'usr2',
         _id: 4ed27326c1d767f70e000003,
         Points: 100 } ] 
  }
  </code></pre>
  
  <p>I don't really know how to handle the variable passed to the Jade page. Whichever thing I do I keep getting the "Unexpected identifier" error.
  Does anyone of you know how do I solve this?</p>
  
  <p>Thanks</p>