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)