Note that there are some explanatory texts on larger screens.

plurals
  1. POCombine Arrays in Order JavaScript
    primarykey
    data
    text
    <p>I have a few arrrays which I am trying to combine in a certain order. For example, lets say I have three arrays:</p> <pre><code>var arrayOne = [1a, 1b, 1c]; var arrayTwo = [2a, 2b, 2c]; var arrayThree [3a, 3b, 3c]; </code></pre> <p>how would I get something like this?</p> <pre><code>var combinedArray = [1a, 2a, 3a, 1b, 2b, 3b, 1c, 2c, 3c] </code></pre> <p><em>EDIT</em></p> <p>Ok, I am going to add a little more to my story here since I have gotten some great responses and answers from everyone. Maybe this will be clearer. I have a SharePoint list which I am getting all of my information from. I am using SPServices to get my data from the list. I am also getting the version history of each list item and placing them into arrays so I can pull the data out of the SPServices loop and use it outside of the SharePoint stuff so I can try to order and display it as I want. (Please do not move this to SharePoint ). This is all going to have to happen at runtime. So here is the first part. I am declaring global variables for each one of my list items:</p> <pre><code>var proModified6 = new Array(); var proHistory = new Array(); var assignedTo = new Array(); var startDate = new Array(); var endDate = new Array(); var status = new Array(); var project = new Array(); var history = new Array(); var listItems = new Array(); var regex = new RegExp(""); var i = 0; </code></pre> <p>Then I am filling the arrays with the SharePoint list info ( I am not going to put them all but each has a call like this one)</p> <pre><code>$().SPServices({ operation: "GetVersionCollection", async: false, webURL: "http://devchrisl01/test", strlistID: "NewProjects", strlistItemID: proID[i], strFieldName: "Title", completefunc: function (xdata, Status) { $(xdata.responseText).find("Version").each(function() { //alert(xdata.responseXML.xml); var xitem = $(this); var ID = xitem.attr('ID'); var Project = xitem.attr('Title'); var Modified = xitem.attr('Modified').split('T')[0]; var ModifiedTime = xitem.attr('Modified').substring(11, 19); //var modifiedUl = "&lt;td&gt;&lt;b&gt;" + Modified + " " + ModifiedTime + "&lt;/b&gt;&lt;/td&gt;"; //$('#versionList'+i+'').append(modifiedUl); project.push(Project); proModified2.push(Modified + ModifiedTime) // just looking at my data here not really part of my problem var data = "&lt;tr&gt;&lt;td&gt;&lt;b&gt;" + Modified + " " + ModifiedTime + "&lt;/b&gt;&lt;/td&gt;&lt;td&gt;" + Project + "&lt;/td&gt;&lt;/tr&gt;"; $('#versionList'+i+'').append(data); }); } }); </code></pre> <p>After is where my question has come into play. I am getting all of my data back I need. I have not found a better way to store all of the list information and pull it out of the SPServices besides using an array for each. The kicker is I am not going to know how many arrays there are going to be or how long. Eventually this is going to be dynamic. (PAIN IN THE ASS ) so here are the arrays:</p> <pre><code>var modifiedDate = [proModified1, proModified2, proModified3, proModified4, proModified5, proModified6]; var projectHistory = [history]; var projectTitle = [project]; var projectAssignedTo = [assignedTo]; var projectStartDate = [startDate]; var projectEndDate = [endDate]; var projectStatus = [status]; </code></pre> <p>Each one is going to be different. There is not going to be the same amount of them either for each user. I have just made my list static to build on first. List dynamics will be another question later :0 </p> <p>Is there going to be a way for me to do with these arrays like I asked in my simple example? See why I went simple first lol.</p>
    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.
 

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