I have a simple one dimensional array but I want to split the long list into two columns using jQuery. How can I achieve this?
var articles = ['article10','article9','article8','article7','article6','article5','article4','article3', 'article2', 'article1'];
for ( var articCounter = articles.length; articCounter > 0; articCounter--) {
document.write('<a href="../articles/' + articles[articCounter-1] + '.pdf" > ' + articles[articCounter-1] + '</a></br>');
} // end for
I don’t want to have to create two different arrays for two different float divs….
I’ve googled this many times but many other methods deal with multidimensional arrays.
Thank you very much for the help in advance.
EDIT: Right now it’s just one long list like so:
Article1
Article2
Article3
….
But I would like to achieve this:

This will split your array into 2 arrays:
Then you can use them where and/or how you want.
Explanation
The 2nd line finds an anchor index (alias -> middle index of division),by which array should be divided into 2 chunks. The array can have
oddandevenlengths,and those 2 situations must be distinguished. As it is impossible to divide odd-length array into 2 equal parts, it must be divided in such way, that 1st chunk will have 1 element more or less,than 2nd chunk.Here, I have implemented first case,that is, 1st chunk will have 1 element more,than 2nd one. Here are the examples of different situations:In table,
number–numbersyntax shows accordingly start and end indexes in array. The division is done by .slice() function.