const str = 'abcde';
// β
Get the last character of a string using charAt()
const last = str.charAt(str.length - 1);
console.log(last); // ποΈ e
// β
Get the last character of a string using slice()
const lst = str.slice(-1);
console.log(lst); // π 'e'
const lst2 = str.slice(-2);
console.log(lst2); // ποΈ 'de'
// β
Get the last character of a string using String.at()
const last_ = str.at(-1);
console.log(last_); // ποΈ e
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)