How could you solve this node.js error of undefined property?
<p>I have this error message of</p>

<p>Cannot read property 'title' of undefined</p>

<p>It worked fine when I used posts.forEach for traversing. but 
It stopped working when used with for loop.
Could you please help?</p>

<p>This is my code</p>

<pre><code>&lt;section class="forum"&gt;
&lt;ul class="pages"&gt;
    &lt;% for (var i = 1; i &lt;= Math.ceil(posts.length / 3); i++) { %&gt;

            &lt;li&gt;&lt;a href="#&lt;%=i%&gt;"&gt;&lt;%= i %&gt;&lt;/a&gt;&lt;/li&gt;

    &lt;% } %&gt;
    &lt;% var pages = i %&gt;

&lt;/ul&gt;
    &lt;div class="tabbedPages"&gt;
        &lt;div class="tabbedPage"&gt;

    &lt;% for (var i = 1; i &lt;= pages; i++) { %&gt;
        &lt;div class="page" id="&lt;%=i%&gt;"&gt;
                &lt;table&gt;
                    &lt;tr&gt;
                        &lt;th&gt;Title&lt;/th&gt;
                        &lt;th&gt;Replies&lt;/th&gt;
                        &lt;th&gt;Last Message&lt;/th&gt;
                    &lt;/tr&gt;
                &lt;% for (var j = (i - 1) * 3; j &lt; (i * 3) ; j++){ %&gt;
                    &lt;tr&gt;
                        &lt;td&gt;

                            &lt;h2&gt;&lt;%= posts[j].title %&gt;&lt;/h2&gt;
                            &lt;h2&gt;&lt;%= posts[j].author %&gt;, 
                            &lt;% var diff = posts[j].date - Date.now %&gt;
                            &lt;% var msec = diff 
                                var dd = Math.floor(msec / 1000 / 60 / 60 / 24);
                                msec -= dd * 100 * 60 * 24;
                                var hh = Math.floor(msec / 1000 / 60 / 60);
                                msec -= hh * 1000 * 60 * 60;
                                var mm = Math.floor(msec / 1000 / 60);
                                msec -= mm * 1000 * 60;
                                var ss = Math.floor(msec / 1000);
                                msec -= ss * 1000;
                            %&gt;
                            &lt;% if (dd &gt;= 1) { %&gt;
                                &lt;%= dd %&gt; days ago 
                            &lt;% } else if (hh &gt;= 1) { %&gt;
                                &lt;%= hh %&gt; hours ago  
                            &lt;% } else if (mm &gt;= 2) { %&gt;
                                &lt;%= mm %&gt; minutes ago 
                            &lt;% } else if (mm == 1) { %&gt;
                                1 minute ago
                            &lt;% } else { %&gt;
                                Moments ago
                            &lt;% } %&gt;

                            &lt;/h2&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;h2&gt;Replies: &lt;%= posts[j].posts.length%&gt;&lt;/h2&gt;



                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;h2&gt;
                                &lt;% if (posts[j].posts.length == 0 ) { %&gt;
                                    Not Available Yet
                                &lt;% } else { %&gt;
                                &lt;%= posts[j].posts[posts[j].posts.length - 1].author %&gt;
                                &lt;% } %&gt;
                                &lt;/h2&gt;
                            &lt;h2&gt;
                            &lt;% var diff = posts[j].date - Date.now %&gt;
                            &lt;% var msec = diff
                                var dd = Math.floor(msec / 1000 / 60 / 60 / 24);
                                msec -= dd * 100 * 60 * 24;
                                var hh = Math.floor(msec / 1000 / 60 / 60);
                                msec -= hh * 1000 * 60 * 60;
                                var mm = Math.floor(msec / 1000 / 60);
                                msec -= mm * 1000 * 60;
                                var ss = Math.floor(msec / 1000);
                                msec -= ss * 1000;
                            %&gt;
                            &lt;% if (dd &gt;= 1) { %&gt;
                                &lt;%= dd %&gt; days ago 
                            &lt;% } else if (hh &gt;= 1) { %&gt;
                                &lt;%= hh %&gt; hours ago  
                            &lt;% } else if (mm &gt;= 2) { %&gt;
                                &lt;%= mm %&gt; minutes ago 
                            &lt;% } else if (mm == 1) { %&gt;
                                1 minute ago
                            &lt;% } else { %&gt;
                                Moments ago
                            &lt;% } %&gt;
                            &lt;/h2&gt;
                        &lt;/td&gt;

                    &lt;/tr&gt;

            &lt;% } %&gt;

            &lt;/table&gt;

    &lt;% } %&gt;
&lt;/section&gt;
</code></pre>

<p>Could you please help me what the heck is wrong with this code?</p>