how could I declare several js array dynamically? For example, here is what tried but failed:
<script type="text/javascript">
for (i=0;i<10;i++)
{
var "arr_"+i = new Array();
}
Thanks!
how could I declare several js array dynamically? For example, here is what tried but failed:
<script type="text/javascript">
for (i=0;i<10;i++)
{
var "arr_"+i = new Array();
}
Thanks!
make it an array of arrays:
var arr = []; // creates a new array .. much preferred method too.
for (var i = 0; i < 10; i++) {
arr[i] = [];
}
You were pretty close depending on what you would like to do..
<script type="text/javascript">
var w = window;
for (i=0;i<10;i++)
{
w["arr_"+i] = [];
}
</script>
Would work, what is your intention for use though?
You can put them all into an array, like this...
var arrContainer = [];
for (i=0;i<10;i++)
{
arrContainer.push(new Array());
}