Why doesn't my for each loop run in IE?
By Saud Rana
There are a few critical points in your code that might fail if conditions are not as you expect. One simple but effective approach is to insert Javascript alert() statements at points through the loop to check the outcome of each condition
There are a few critical points in your code that might fail if conditions are not
as you expect. One simple but effective approach is to insert Javascript alert()
statements at points through the loop to check the outcome of each condition,
e.g.
if (data) {
alert('The data variable evaluates to true.');
// Else none of the following executes...
...
It is not clear where the variable data originates and whether you would always expect
it to have a value. Where does the key reference below originate, what does it
refer to?
...
for (key in data[i]) {
alert('Data value ' + i + ' = ' + data[i]);
}
...
Does this loop run at all? What values do you get? This simple alert() based technique
can give quick insights to where your code may fail. Some browser add-ons and
developer consoles allow you to step through Javascript as it executes and inspect
values in more detail.
Why doesn't my for each loop run in IE? (675 Views)