How to get the last character of the string:

"linto.yahoo.com."

The last character of this string is "."

How can I find this?

16 s
16

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";

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *