Substring with reverse index
var str = "xxx_456"; var str_sub = str.substr(str.lastIndexOf("_")+1);
If it is not always three digits at the end (and seperated by an underscore). If the end delimiter is not always an underscore, then you could use regex:
var pat = /([0-9]{1,})$/; var m = str.match(pat);
The substring method allows you to specify start and end index:
var str = "xxx_456";
var subStr = str.substring(str.length - 3, str.length);
slice
works just fine in IE and other browsers, it's part of the specification and it's the most efficient method too:
alert("xxx_456".slice(-3));
//-> 456
slice Method (String) - MSDN
slice - Mozilla Developer Center