News

JavaScript string handling - oh come on, IE!

Written by DP | Aug 24, 2009 9:26:00 AM

Anyone want to guess what the result of this bit of javascript is?

<span style="color: #0000ff">var</span> myString = &quot;<span style="color: #8b0000">abc</span>&quot;;
<span style="color: #0000ff">alert</span>(myString[2]);

Let's see, shall we?

Firefox:

Google Chrome:

Safari:

IE7:

Admittedly IE8 treats strings the same way everyone has been treating them since the 1970s, but at the rate users pick up the newer versions, we're going to have to carry this around for a good many years yet.

Sigh.