javascript substr Function

substr() is a String prototype, it returns a sub string.

String.substr(start [, length]): if the length is not specified, it will subtract from the start position to the end of the string.

var str = "javascript endmemo";
alert(str.substr(5)); //script endmemo
alert(str.substr(5,10)); //scrip endm

If the start position < 0, it will start from the end:
var str = "javascript endmemo";
alert(str.substr(-5)); //dmemo

substr() supports unicode:
var str = "中国人民银行";
alert(str.substr(-5)); //国人民银行
alert(str.substr(2,4)); //人民银行

endmemo.com © 2017  Terms of Use | Home