Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create and print list of sub arrays out of one long array
    primarykey
    data
    text
    <p>I have a long array of strings that will have a varying length because I'm pulling the strings from a database table that will be filled dynamically by user submission, however, that long array will be comprised of a repeating set of 6 variables. So I want to slice it at every 6th index, turning what I've sliced into an array, and then printing the list of those sub arrays to the page. This is what I have so far: </p> <pre><code>//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 &lt; 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 &lt; 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload