I have a problem when I want to dynamically iterate an array with another array
var str = Array();
str[0]= "foo";
str[1]= "x";
console.log(str); // ["foo", "x"]
var arr = Array();
arr.foo = "Example Text";
arr.x = "Example Text 2"
console.log(arr) //[foo: "Example Text", x: "Example Text 2"]
for (var i = str.length - 1; i >= 0; i--) {
console.log(arr.str[i]);
}
Error:'Uncaught TypeError: Cannot read property '1' of undefined at :8:21'
What you have to access is the value
i
of your first array, which returns the key you are looking for in your second array.arr['foo'], arr['x']