IE and its broken substr()

substr() is a very simple function for working with strings. It's been around forever, and is well documented. I recently had need to find the last character of a string in javascript. Everything was working fine in Firefox and Chrome, but IE was breaking.

'abcdef'.substr(-1,1)

That is, start at 1 character from the end (-1) and return 1 character. In all other browsers this returns 'f' but in IE it returns 'a'.

Leave A Reply
All content licensed under the Creative Commons License