quote:
Originally posted by Volv
matty, unless I'm mistaken, that doesn't allow you to get the element's index in the array and hence you can't get the corresponding response =/
No, that's why the variable i is there! Actually, it doesn't matter what method you choose, it'll always give you a loop through the array. However,
if you're trying this on an object, you have to use Matty's method because an object doesn't have numeral indexes. Instead, the i variable contains the key name of the object value. For example:
code:
var FruitColors = function() {
this.Banana = "yellow"; //"Banana" is not numeral and therefore you can't use a number to iterate through this object
this.Apple = "red";
this.Pear = "green";
}
var MyObject = new FruitColors();
for(var i in MyObject) {
Debug.Trace("The color of "+i+"s is "+FruitColors[i]); //Output: "The color of Bananas is yellow" etc.
}