Javascript sub string nuances

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.

blog comments powered by Disqus

Categories

xhtml 1.1 compliant   xhtml 1.1 compliant