'abc'.slice(-2);
// Get last n characters from string
var name = 'Shareek';
var new_str = name.substr(-5); // new_str = 'areek'
str.charAt(str.length-1)
const myString = "linto.yahoo.com.";
const stringLength = myString.length; // this will be 16
console.log('lastChar: ', myString.charAt(stringLength - 1)); // this will be the string
Run code snippet
//Gettimg the last character of an unknown string;
//using function Expression;
const gettingLastChar = function(userInput){
return userInput.substring(userInput.length -1);
//for Debugging;
let letsDebug = `${userInput.substring(userInput.length -1)}`;
console.log(letsDebug);
}
// Get The Length Of The String.
function strLength(x){
var counter = 0;
while(x[counter] !== undefined){
counter++;
}
return counter;
}
var str = prompt("Write your string ...",''); // Get String From User.
var The_Length = strLength(str); //
var lastChar = counter - 1; // The Index Of Last Letter.
console.log(`The Length Of Your String is ${counter}`);
console.log(`The Last Char In Your String Is ${str[lastChar]}`);