My javascript for loop is only printing 1 rows out of an array with 3 rows

I don't know what the right condition should be on a for loop that loops through an array that will have a varying length depending on how many rows are in a table that I pull from and add to the array. The array currently has three rows, but the for loop only prints out two. My code: //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
rows to the div, only one gets printed. I've tried changing the comparison operator to
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("
" + search[i].join(' ') + "Interested?
"); } };// closes for },//closes success error: function(error) { alert("Error: " + error.code + " " + error.message); } }); //closes find
did you check if the query response is returning all object you need?

以上就是My javascript for loop is only printing 1 rows out of an array with 3 rows的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准