title: Using pug/jade to iterate over an array of objects
body: <p>Using node with express, I've queried my database and returned an array of objects - verified by console logging the array.</p>
  
  <p>I now need to loop through the array of objects, grab the key/value pairs I need and print them as a list to the html using pug.</p>
  
  <p>Pug's iteration documentation says this:</p>
  
  <pre><code>ul
    each val in [1, 2, 3, 4, 5]
      li= val
  </code></pre>
  
  <p>In my app.js file, this is the code I'm using to render the page:</p>
  
  <pre><code>app.get('/', function (req, res) {
          res.render('index', {storeItems: results});
  });
  </code></pre>
  
  <p>In my pug file, I'm using this syntax.</p>
  
  <pre><code>.col-6
    ul.list-group
      each storeItem in storeItems
         li.list-group-item storeItem.product_name
  </code></pre>
  
  <p>Running this code generates the following error.</p>
  
  <p>Cannot read property 'length' of undefined. It says the error is on this line: </p>
  
  <pre><code>each storeItem in storeItems
  </code></pre>
  
  <p>I'm not seeing where I need to declare the length of the array in the pug documentation. What am I missing? I've tried adding .length to the storeItems - generates the same error. I've tried using the = sign after the li which also generates the same error.</p>
  
  <p><a href="https://i.stack.imgur.com/yvc9p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yvc9p.png" alt="enter image description here"></a></p>