Hi all,
I am facing the following problem:
I load a set of data from an XML file and I need to map this in JavaScript. Either in an associative array or in an object (you tell me which ?.
[CODE]var myArray = Array();
for(iCount = 0; iCount < rootNode.childNodes.length; iCount++) {
currentChild = rootNode.childNodes[kCount];
if(currentChild.nodeName.substring(0,1) != ‘#’) {
//Is a tag node (does not start with #)
varNodeName = currentChild.nodeName;
myArray[iCount] = Array();
if(currentChild.childNodes.length > 0) {
//Has a value (textnode child)
escalationData[iCount][varNodeName] = currentChild.firstChild.data;
} else {
//No children, set empty value
escalationData[iCount][varNodeName] = ”;
}
}
}
But what is happening is that every myArray[iCount] entry only has one property: the las one which has been set in the loop. So this line:
[CODE]escalationData[iCount][varNodeName] = currentChild.firstChild.data;
Is constantly overwriting the previously set value, although varNodeName always has a different value (as I tested by printing it within the loop).
Any hints on how to solve this situation? I thought about using objects, but how do I set a propertyname using avalue?
myArray.variableName does not work, obviously.
Any hints greatly appreciated!
Cheers