Is it possible to use an incremental value within a variable name whilst declaring it within a loop?

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2010-06-03T08:52:04Z Indexed on 2010/06/03 8:54 UTC
Read the original article Hit count: 181

Filed under:
|

Hi,

I'm creating function which will read different XML files each time that will contain different amounts of the same nodes.

I have already created a loop which stores the ID of each node into an array, and now I want to create variables for each array member which store attributes of the node with each ID.

Because the number of nodes will be different for every XML document my function reads, I cannot manually assign variables for the attributes of each node ID not knowing how many to assign, so I have created a loop which runs specific to the number of items I have stored in the array. Inside this loop I was hoping to have something like:

for (i=0; i<array.length; i++)
{
    var ID + i + width = exampleheight
    var ID + i + height = exampleheight
}

I know this doesn't work, but was trying to outline what I am looking to find out. Is it possible to use some kind of variable or random number when declaring a variable?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about variables