1

I have a dynamic created array:

var myArray = ['content_1','content_2','content_3','content_4'];

Other times my array could have more items in as such:

var myArray = ['content_4','content_4','content_new','content_new','content_new','content_new','content_new'];

My if statement looks like:

if (myArray.length > 8) { //then do something }

If myArray has more then 8 items in the array, create a new one, each array can only hold 8 items though. So my first array could have 40 items in, 20 items in, or more... I never know, how could I split these into dynamic arrays, is there a way I can do this?

After the 8th item in myArray push those 8 into a new array, then the next 8 (if applicable) and so forth

Khalid
  • 4,730
  • 5
  • 27
  • 50
pourmesomecode
  • 4,108
  • 10
  • 46
  • 87

1 Answers1

0

You'd either have to store your arrays in another array or create a new variable for each array. Personally I'd use an array to store all the arrays so you can still look through all of them when you need to.

var arrays = [['item', 'item'], ['item','item']];

if(arrays[arrays.length].length === 8) {
    arrays.push(['new array']);
}

Obviously this won't work for every scenario but it would have to be something similar.

silverlight513
  • 5,268
  • 4
  • 26
  • 38