I would like to ask you if there is any function in js/jquery that creates 2d array from two 1d arrays.
I know that i can do it manually like:
var output = new Array(table1.length);
for(var i=0; i<table1.length; i++)
{
output[i] = new Array(2)
output[i][0] = table1[i]
output[i][1] = table2[i]
}
But maybe there is any function which does it for me ?
You can always write your own function, it’s not that difficult. Though 1 tip/recommendation: Don’t use the
Arrayconstructor, because as soon as you start using variables to instantiate new arrays, in a loose typed language such as JS, it might produce unexpected results.Take this for example:
that said, here’s an example function:
That should give you what you need