Jump to content

ARRAY Objects


Lefu

Recommended Posts

hello guys,

 

I have an array like

var letters = new Array('a',...,'i');

then I have created arrays dynamically like

var pgA= new Array('a1','a2');

var pgB= new Array('b1','b2');

and so on untill pgZ = new Array('z1','z2');

I want to have a loop like

for (i = 0; i<9; i++)

{

  alert('pg'+toUpperCase(letter));

}

output is "pgA" not the contents.

 

I want to work with arrays in the pgA .. pgZ

 

without having to write pgA to pgZ manually in their own separate loops.

Thank you for you help and I hope you understand what I wanna do here.

 

Link to comment
Share on other sites

first...instead of having separate variables, let's utilize JSON:

 

var pg = {
  'A' : [ 'a1', 'a2' ],
  'B' : [ 'b1', 'b2' ]
};
alert(pg['A']);

 

you can also automate the filling of the array. but, what exactly are you trying to accomplish...you might be able to do this without building that massive object

Link to comment
Share on other sites

Thank you rhodesa,

 

you sugestion worked the exact way I need.

 

I have sudoku cells and they are grouped in 9 cells. now I can add this module and it will be easy to solve problems for players who are still learning the game.

 

Thanx once again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.