[Javascript] How to select last three characters of a given string?
I want to return last three characters of a given string, How to do that in Javascript?
1 Answer
4 years ago by Jahaan
You can use either substring() or slice() methods to select only last three characters of a given string. Check the usage as shown below:
let str= 'This is a test message'
console.log(str.slice(str.length-3, str.length)); // Outputs age
console.log(str.substring(str.length-3, str.length)); // Outputs age
4 years ago by Meera