JavaScript obtenga el último personaje en cadena
var hello = "Hello World";
var lastCharOfHello=hello.slice(-1);//d
Grepper
var hello = "Hello World";
var lastCharOfHello=hello.slice(-1);//d
var str = "Hello";
var newString = str.substring(0, str.length - 1); //newString = Hell
'abc'.slice(-2);
function test(words) {
var n = words.split(" ");
return n[n.length - 1];
}
// Get last n characters from string
var name = 'Shareek';
var new_str = name.substr(-5); // new_str = 'areek'
function test(words) {
var n = words.indexOf(" ");
var res = words.substring(n+1,-1);
return res;
}