我有一个长度不等的长字符串数组,因为我从数据库表中提取字符串,这些字符串将由用户提交动态填充,但是,该长数组将由一组重复的 6 个变量组成。所以我想在每 6 个索引处对它进行切片,将我切片的内容转换为一个数组,然后将这些子数组的列表打印到页面上。这是我到目前为止所拥有的:
//I'm using Parse as my database and the find() method is one way you query it.
var search = [];
query.find({
success: function(results) {
//loop through results to get the key-value pair of each row
for (i = 0; i < results.length; i++){
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");
//Here I'm pushing the row of the six variables into an array, but since there will be multiple rows on the table from multiple submissions, the array will contain however many rows there are.
search.push(activity, scene, neighborhood, date, details, time);
//my second array
var search2 = [];
//This is that part I'm unsure of. I want to loop through the search array slicing it at every 6th index creating multiple sub arrays. I then want to write the list of those sub arrays to the page
for(i=0; i < search.length; i+=6){
search2 = search.slice(0,6);
}
//this is the div I want to write the arrays to.
$("#mainDiv").text(search2);
};// closes success function