Lefu Posted June 12, 2009 Share Posted June 12, 2009 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. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 12, 2009 Share Posted June 12, 2009 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 Quote Link to comment Share on other sites More sharing options...
Lefu Posted June 12, 2009 Author Share Posted June 12, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.