How to Get the Last Characters of a String
There are several methods used to get the last character of a string. In this tutorial you can find the simple solution for your case.
The substr() method returns a section of the string, starting at the specified index and continuing to a given number of characters afterward.
Another method is .slice() which is used to get the last characters of the string:
The .slice() method takes out parts of a string and returns the extracted parts in a new string. This method is a better method to use for getting the last characters as it provides cross-browser compatibility.
Typing the property correctly is very important. If you mistype it by calling str.length() instead of just str.length, it will not work.