AQuee
0
Q:

how to get last string in javascript

var hello = "Hello World";
var lastCharOfHello=hello.slice(-1);//d
11
var str = "Hello";
var newString = str.substring(0, str.length - 1); //newString = Hell
14

var str = "HELLO WORLD";
var res = str.charAt(str.length - 1); 
3
// strips all punctuation and returns the last word of a string
// hyphens (-) aren't stripped, add the hyphen to the regex to strip it as well
function lastWord(words) {
    let n = words.replace(/[\[\]?.,\/#!$%\^&\*;:{}=\\|_~()]/g, "").split(" ");
    return n[n.length - 1];
}
1
'abc'.slice(-2);
2
var lastChar = myString[myString.length -1];
3

New to Communities?

Join the community