« Back to APIs

jabberwerx IE8 and for in loops

Combination View Flat View Tree View
Threads [ Previous | Next ]
Hi,,
i'm facing a problem with IE8 and integrating the jabberwerx libs. I use for..in-loops to walk through arrays. in IE8 i get a new item in the array. it's the function indexOf. It seems that jabberwerx extends the Array-Prototype with that function. is there an easy way to solve the problem without looking for every for...in-loop  and add an if-statement to check for hasOwnProperty()?
 
regards
Mark

Hi Mark,
I tend to avoid the for .. in loops for this kind of reason. You can use jQuery.each instead to iterate over an Array or Object. jabberwerx.js bundles jQuery, and defines window.jQuery if not defined yet. So window.jQuery (identical to jabberwerx.jQuery) should be available in your application to do iterate over arrays like this:
var myArray = [1, 2, 3];
jQuery.each(myArray, function(index, element) {
    // do something with element
});
Hope this helps, Thomas