我的javascript for循环只打印了3行数组中的1行

我的javascript for循环只打印了3行数组中的1行,javascript,for-loop,conditional-statements,Javascript,For Loop,Conditional Statements,我不知道for循环的正确条件应该是什么,该循环通过一个数组进行循环,该数组的长度取决于我从中提取并添加到数组的表中的行数。数组当前有三行,但for循环只打印出两行。我的代码: //my database query query.find({ success: function(results) { //this for loop works fine for (i = 0; i < results.length; i++){ eventID = res

我不知道for循环的正确条件应该是什么,该循环通过一个数组进行循环,该数组的长度取决于我从中提取并添加到数组的表中的行数。数组当前有三行,但for循环只打印出两行。我的代码:

//my database query 

query.find({
  success: function(results) {

//this for loop works fine

    for (i = 0; i < results.length; i++){

        eventID = results[i].id;
       activity = results[i].get("activity");
        scene = results[i].get("location");
        neighborhood = results[i].get("neighborhood");
        date = results[i].get("date");
        details = results[i].get("details");
        time = results[i].get("time");
        objIDs.push(eventID);

//each row gets pushed into an array

       search.push([activity, scene, neighborhood, date, details, time]);


        //I empty a div on a page that uses the ajax load() method to load an html page.I replace that html with the array of query results. 

             $('#div1').empty();

       //there are currently 3 rows in my array, but when I loop through it and append() the </br>rows to the div, only one gets printed. I've tried changing the comparison operator to </br>different things but nothing works. I'm definitely getting all the rows from the query because when I alert() the search array I see all the rows. 

       for (i = 0; i <= search.length; i++) {

            $('#mainDiv').append("<div id='event'>" + search[i].join(' ') + "<a href='#' class='interested'>Interested?</a></div>");
        } 

    };// closes for
    },//closes success

  error: function(error) {
    alert("Error: " + error.code + " " + error.message);
  }
}); //closes find 
//我的数据库查询
查询.查找({
成功:功能(结果){
//这个for循环工作得很好
对于(i=0;i行附加到div()时,只打印一行。我尝试将比较运算符更改为
不同的内容,但没有任何效果。我肯定会从查询中获取所有行,因为当我提醒()搜索数组时,我会看到所有行。 对于(i=0;i虽然下面的内容是一个问题,但它可能不是问题。但是,由于我无法删除此帖子(我必须登录还是什么?),它仍然是一个工件。请注意它,即使问题是其他的


代码在嵌套循环中使用相同的
i
变量,并在两个循环中递增
i


使用不同的变量。

您在
for
中有一个
for
,当您对它进行迭代时,您的搜索尚未完全初始化

};// closes for

    for (i = 0; i <= search.length; i++) {

        $('#mainDiv').append("<div id='event'>" + search[i].join(' ') + "<a href='#' class='interested'>Interested?</a></div>");
    } 

},//closes success
};//关闭

对于(i=0;您是否检查了查询响应是否返回了您需要的所有对象?
search
在何处初始化?search
中是否有3行?results
中是否有3行?