views:

222

answers:

2

I used to access individual characters of a string using string[n].

But when I do this in IE8 it always returns undefined when I do this.

I can use string.substr(n, 1) to do the same thing, but the syntax is much longer. Why did they do this?

+4  A: 

You can use string.charAt(n) - I'm not sure when string[n] became valid or why it's been removed.

Edit: I've tested in IE 6 and 7 and string[n] didn't work in any of them.

Greg
Link is down at the moment :/
Greg
+5  A: 

That form of character access is not part of the ECMAScript standard, but is implemented by some VMs. I would go with charAt as RoBorg suggested and avoid unstandardized features.

Zach