Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array making loop

Status
Not open for further replies.

alias301

Programmer
Joined
May 25, 2008
Messages
1
Location
US
Is it possible to make a loop that makes a defined number of arrays that makes a defined number of statments?
 
I'm not sure I understand what the second part of the question means (arrays making statements??), but to define some global variables in a loop, you can use:

Code:
function createGlobalArrays() {
   var arrayNamePrefix = 'myArray';
   var numArrays = 3;

   for (var loop=1; loop<=numArrays; loop++) {
      window[arrayNamePrefix + loop] = [];
   }
}

createGlobalArrays();
alert(myArray1.length);
alert(myArray2.length);
alert(myArray3.length);

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top