Skip to content
Advertisement

Splitting of array into multiple arrays

I have an array of dynamic length L1. I need to split this array into L2 number of arrays each having LEN[i] numbers from the original array.

JavaScript

I have tried a lot of ways but nothing seems to be working. Any help would be greatly appreciated.

Advertisement

Answer

If you need such a variable array length of chunks then you can create your own functionality using simple foreach and array_splice like as

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement