JSFiddle - React, Tailwind, and code Playground
by davestein
HTML
<h3>Using native</h3>
Will log 6 times no matter what version of IE8.
<br /><br />
<h3>Using .map</h3>
In IE8, on XP ( aka the real IE8 ), it will log 6 times - once for a_1-3 and once for 1-3.<br />
In IE8 mode on Windows 7, it works fine.<br />
<br />
Does jQuery know about this bug and compensate for it? If so, it seems there's a bug when using the "real" IE8.
JavaScript
// Object to iterate
var freshObject = function() {
return {
a_1 : 1,
a_2 : 2,
a_3 : 3
};
};
// Function to remove unwanted index and add the new one
var swap = function( obj, val, index ) {
console.log( index, ' ', val );
var new_index = index.replace( 'a_', ' ', '' );
obj[new_index] = val;
delete( obj[index] );
};
var x = freshObject();
console.log( 'Native results:' );
for ( index in x ) {
swap( x, x[ index ], index );
}
x = freshObject();
console.log( '$.map results:' );
$.map( x, function( val, index ) {
swap( x, val, index );
});