Archive for November, 2009

Javascript sub string nuances

Wednesday, 25th November, 2009

I’m surprised I’ve not run into this before but Javascript has two sub string methods.

[String].substr(start, length);
[String].substring(indexA, indexB);

To clarify by example:

var name = "Greg Knapp";
alert(name.substr(5, 5)); // Knapp
alert(name.substring(5, 10)); // Knapp

Minor but caught me out this afternoon.

You are currently browsing the greg's weblog – the more I learn, the less I know weblog archives for November, 2009.

Categories

xhtml 1.1 compliant   xhtml 1.1 compliant