# Referencing array items with an id pulled from the array

**URL:** <https://forum.kirupa.com/t/referencing-array-items-with-an-id-pulled-from-the-array/197675>\
**Category:** Uncategorized\
**Created:** [August 18, 2006, 4:05am UTC](https://forum.kirupa.com/t/referencing-array-items-with-an-id-pulled-from-the-array/197675 "2006-08-18T04:05:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dboy](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@dboy](https://forum.kirupa.com/u/dboy)\
**Post date:** [August 18, 2006, 4:05am UTC](https://forum.kirupa.com/t/referencing-array-items-with-an-id-pulled-from-the-array/197675/1 "2006-08-18T04:05:20Z")

</div>

I have been modifying one of the Kirupa tutorials about loading external xml data and arrays. I have it successfully working, but i would like to figure out how to take it one step further. I want to be able to designate a each item in the arrays with an id rather than an iterative variable number and cannot figure out how to do it.

This is a snippet from the xml file:

\<projects\>  
\<item\>  
\<id\>13\</id\>  
\<projectname\>First Project\</projectname\>  
\<location\>Anytown, USA\</location\>  
\<units\>60\</units\>  
\</item\>  
\<item\>  
\<id\>33\</id\>  
\<projectname\>Second Project\</projectname\>  
\<location\>Sometown, USA\</location\>  
\<units\>132\</units\>  
\</item\>  
\</projects\>

I am currently populating an array this way:

total = xmlNode.childNodes.length;  
for (i=0; i\<total; i++) {  
id\* = xmlNode.childNodes\*.childNodes[0].firstChild.nodeValue;  
projectname\* = xmlNode.childNodes\*.childNodes[1].firstChild.nodeValue;  
plocation\* = xmlNode.childNodes\*.childNodes[2].firstChild.nodeValue;  
units\* = xmlNode.childNodes\*.childNodes[3].firstChild.nodeValue;  
}

but that just gives me references to: projectname1, projectname2 etc.  
I would like to figure out how to get the \<id\> value from the loaded xml file connected to the variable name of each item in the array so that i can refer to the variables this way: projectname13, projectname33, etc.

Does this make sense? Can anyone help?
