userimage

Find the last character of the string using Javascript

I have a requirement like to find out only the last character of a string.

e.g the string is "The bit position of the given number is 5". Then the code should return me the last character as "5"

userimage

You can able to achieve your result by using JavaScript predefined slice method. See below,


var str = "The bit position of the given number is 5";

alert("Last char of the string : "+str.slice(-1) );

Answer is