how to get the last character of a string?

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)