1var str = "Hello";
2var newString = str.substring(0, str.length - 1); //newString = Hell
1// To get the last "Word" of a string use the following code :
2
3let string = 'I am a string'
4
5let splitString = string.split(' ')
6
7let lastWord = splitString[splitString.length - 1]
8console.log(lastWord)
9
10/*
11Explanation : Here we just split the string whenever there is a space and we get an array. After that we simply use .length -1 to get the last word contained in that array that is also the last word of the string.
12*/
13