-3

If I have an array like this var arr = [1,3,2,4,8,9,8,6,9]

How can I equally split the array to multiple arrays in a object like this

{ '0': { num: [ 1,3,2 ] },
  '1': { num: [ 4,8,9 ] },
  '2': { num: [ 8,6,9 ] }
}

Thanks

Edit: The numbers of multiple arrays can change. Example I want to divide into three thirds of existing array or four quarters in som cases.

roYal
  • 197
  • 1
  • 2
  • 16
  • 3
    Possible duplicate of [How to split a long array into smaller arrays, with JavaScript](http://stackoverflow.com/questions/7273668/how-to-split-a-long-array-into-smaller-arrays-with-javascript) – kirkpatt Apr 12 '16 at 16:10

1 Answers1

0

It was easier than I though.

    var n = 0;
    for(var i = 0; i < Arr.length; i++) {

        PLAYER_LIST[n].countries.push(Arr[i]);
        n +=1;
        if(Object.keys(PLAYER_LIST).length == n){
            n = 0;
        }
    }

Now my arrays have equal amount of numbers

roYal
  • 197
  • 1
  • 2
  • 16