Share
How to get the last character of a string in Javascript
Question
How can I get the last character of a string dynamicaly using Javascript?
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Answer ( 1 )
You can get the last character of a string by decrementing the string length by 1.
The length property gives you the ability to determine the number of elements in an array, or the number of characters in a string.
For example:
To get the last letter or character dynamically, you can do this since the string has an index of “0”: