js get last two characters of string code example
Example 1: javascript string get last two character
var member = "my name is Mate";
var last2 = member.slice(-2);
alert(last2);
Example 2: js get last 4 digits
const id = "ctl03_Tabs1";
console.log(id.slice(id.length - 5));
console.log(id.slice(id.length - 1));
Example 3: javascript get last n characters of string
'abc'.slice(-1);
Example 4: js get first 3 characters of string
const string = "0123456789";
console.log(string.slice(0, 2));
console.log(string.slice(0, 8));
console.log(string.slice(3, 7));
Example 5: find the last occurrence of a character in a string javascript
str.lastIndexOf(searchValue[, fromIndex])