I am trying to convert a simple array to a multidimensional array.
The Array I currently have
Array = (1, 2, 3, 4);
I would like to convert this Array to be like this
Array = ([1, 2], [3, 4]);
Any help is welcome, thanks already.
I am trying to convert a simple array to a multidimensional array.
The Array I currently have
Array = (1, 2, 3, 4);
I would like to convert this Array to be like this
Array = ([1, 2], [3, 4]);
Any help is welcome, thanks already.
This worked for me:
function TwoDimensional(arr, size)
{
var res = [];
for(var i=0;i < arr.length;i = i+size)
res.push(arr.slice(i,i+size));
console.log(res);
}
Pretty easy when it works! Thanks