So I’ve been checking around for a while but couldn’t find anything…at least useful. So here is what I want to accomplish:
a = new Array();
b = new Array();
a[0] = 1;
a[1] = 2;
b[0] = a;
It is not do-able, at least with the way above. How can I do that? Is there any other way to do this? Of course, there are plenty of ways to do what want to do but I want to do this with arrays. 😉
Thanks in advance 😉
You can (and probably should) do something like this instead:
…or you could do it like this.
It’s generally considered good practice to use the literal syntax when declaring arrays and objects instead of invoking the constructor, so
var foo = [], bar = {};.Also, you should use the
varkeyword when defining variables, so they don’t leak into the global scope.