Skip to content Skip to sidebar Skip to footer

Get last 10 characters from a string using Java script

Reading Time: < 1 minute

If you want to get last 10 or 5 or nth characters from a string using java script, this can be done very easily.substr function can be use to this.
My string is “”
I want to get 2012/09.This can be get like this.

var myString  = '';
var newString = myString.substr(myString.length - 8);
alert(newString); //  2012/09/

Further you want to remove these Forwardslashes(/) this can be done like this.

var myString  = '';
myString = myString.replace(/\/$/,'');

More info Java script remove backslashes and forwardslashes from a string