How to get the last character of the string:
"linto.yahoo.com."
The last character of this string is "."
How can I find this?
An elegant and short alternative, is the String.prototype.slice
method.
Just by:
str.slice(-1);
A negative start index slices the string from length+index
, to length
, being index -1
, the last character is extracted:
"abc".slice(-1); // "c";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With