JS 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 perschon";
alert(str.substr(5)); //cript perschon
alert(str.substr(5,10)); //cript endm


If the start position < 0, it will start from the end:

var str = "javascript perschon";
alert(str.substr(-5)); //dmemo


substr() supports unicode:

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


convert.idontcarewhatyouthink.net © 2021  Terms of Use | Home