title: Cannot read property 'length' of undefined node.js
body: <p>I have some JSON I'm passing into Node.js and I'm trying to parse through it and display it on the page. However, after searching around on Stack Overflow and trying out various solutions (currently reading <a href="https://stackoverflow.com/questions/21239251/how-to-get-complex-json-object-and-render-it-in-views-in-node-js">this</a>), I'm receiving this error in return: </p>
  
  <pre><code>TypeError: D:\Programming\node\yale\views\index.jade:10
      8|          //- p= post.comments[1].data
      9|          each comment in post.comments
    &gt; 10|                 each text in comment.data
      11|                     p= text.from.name
      12| 
      13| 
  
  Cannot read property 'length' of undefined
      at $$l (eval at &lt;anonymous&gt; (D:\Programming\node\yale\node_modules\jade\lib\jade.js:172:8), &lt;anonymous&gt;:122:31)
      at $$l (eval at &lt;anonymous&gt; (D:\Programming\node\yale\node_modules\jade\lib\jade.js:172:8), &lt;anonymous&gt;:153:4)
      at eval (eval at &lt;anonymous&gt; (D:\Programming\node\yale\node_modules\jade\lib\jade.js:172:8), &lt;anonymous&gt;:160:4)
      at eval (eval at &lt;anonymous&gt; (D:\Programming\node\yale\node_modules\jade\lib\jade.js:172:8), &lt;anonymous&gt;:301:4)
      at eval (eval at &lt;anonymous&gt; (D:\Programming\node\yale\node_modules\jade\lib\jade.js:172:8), &lt;anonymous&gt;:311:21)
      at res (D:\Programming\node\yale\node_modules\jade\lib\jade.js:173:38)
      at Object.exports.render (D:\Programming\node\yale\node_modules\jade\lib\jade.js:269:10)
      at Object.exports.renderFile (D:\Programming\node\yale\node_modules\jade\lib\jade.js:305:18)
      at View.exports.renderFile [as engine] (D:\Programming\node\yale\node_modules\jade\lib\jade.js:290:21)
      at View.render (D:\Programming\node\yale\node_modules\express\lib\view.js:76:8)
  </code></pre>
  
  <p>Here's my JSON:</p>
  
  <pre><code>[
      {
          "id": "362285220481827_740014816042197",
          "from": {
              "id": "1677018201",
              "name": "ABC"
          },
          "message": "Yo!",
  
  
          "comments": {
              "data": [
                  {
                      "id": "740018622708483",
                      "from": {
                          "id": "100003969443486",
                          "name": "XTZ"
                      },
                      "message": "Hey!",
                      "can_remove": false,
                      "created_time": "2014-06-14T17:18:48+0000",
                      "like_count": 0,
                      "user_likes": false
                  }
              ],
              "paging": {
                  "cursors": {
                      "after": "NzQ0MTMxNTc1NjMwNTIx",
                      "before": "NzQwMDE4NjIyNzA4NDgz"
                  }
              }
          }
      }
  ]
  </code></pre>
  
  <p>Index.jade</p>
  
  <p>extends layout</p>
  
  <pre><code>block content
      each post in datas 
          div(id='post')
              p= post.from.name
              p= post.message
              //- p= post.comments[1].data
              each comment in post.comments
                  each text in comment.data
                      p= text.from.name
  </code></pre>
  
  <p>Index.js</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var fs = require('fs');
  var path = require('path');
  
  var file = '../public/sample.json';
  var filePath = path.join(__dirname, '../public/sample.json');
      /* GET home page. */
  router.get('/', function(req, res) {
      fs.readFile(filePath, 'utf8', function(err, data) {
          if(err) {
              console.log(err);
          } else {
              data = JSON.parse(data);
              res.render('index', { datas: data });
              console.log(data);
          }
  
      });
  
  });
  
  module.exports = router;
  </code></pre>
  
  <p>My question is, how do I retrieve the data inside the <code>Comments</code> object? Thanks for your help!</p>