I'm so confused. The problem is that an object loses its values in a loop depending on how you access it. If I access via variables everything works fine. If I use static expressions (just the same as the variables) I don't have the right value. But let's look at the code:
THE FUNCTION ITSELF:
//Creating function with an input parameter (inputString)
function weirdBehaviour(inputString){
//initializing the outputObject which will be returned
var outputObject = {PROP1: "", PROP2: ""}
// Loop through the return-Object
for(x in outputObject){
// Split input at <PROP1> etc.
var res = inputString.split("<" + x.toString() + ">");
// Split "splitted input" again at </PROP1> etc.
var res2 = res[1].split("</" + x.toString() + ">");
// res2[0] is now the String between <PROP1></PROP1>
outputObject.x = res2[0];
// Log gives x and the value assigned to x
console.log("-LOOP-START--------------------------------------");
console.log("This works: ");
// This works just fine
console.log(x.toString() + ": " + outputObject.x);
console.log("This doesn't: ");
// Should be exactly the same but isn't
console.log("PROP1: " + outputObject.PROP1);
console.log("PROP2: " + outputObject.PROP2);
console.log("-LOOP-END----------------------------------------");
}
}
ACCESS EXAMPLE:
weirdBehaviour("<PROP1>String between prop1-tags</PROP1><PROP2>Prop2-Tag-String</PROP2>");
The output:
PROTOKOLL: -LOOP-START--------------------------------------
PROTOKOLL: This works:
PROTOKOLL: PROP1: String between prop1-tags
PROTOKOLL: This doesn't:
PROTOKOLL: PROP1:
PROTOKOLL: PROP2:
PROTOKOLL: -LOOP-END----------------------------------------
PROTOKOLL: -LOOP-START--------------------------------------
PROTOKOLL: This works:
PROTOKOLL: PROP2: Prop2-Tag-String
PROTOKOLL: This doesn't:
PROTOKOLL: PROP1:
PROTOKOLL: PROP2:
PROTOKOLL: -LOOP-END----------------------------------------
I'm so confused... So so strange. I hope someone can help.
Thanks and regards, OL