Method 1: Slice()
slice() the method extracts a section of a string and returns it as a new string, without modifying the original string. So here we find only the last character so we use -1 parameter for the slice function.
var str = 'codermen'; var ans = str.slice(-1); console.log(ans);
Another example of slice()
var str = 'codermen'; var ans = str.slice(-2); console.log(ans);
Method 2: lenght proprties
const str = "codermen"; const stringLength = str.length; // string length is 8 console.log(str.charAt(stringLength - 1));
I hope its help you.