EDIT: As others have pointed out, use slice(-5) instead of substr. However, see the .split().pop() solution at the bottom of this answer for another approach.

Original answer:

You'll want to use the Javascript string method .substr() combined with the .length property.

var id = "ctl03_Tabs1";
var lastFive = id.substr(id.length - 5); // => "Tabs1"
var lastChar = id.substr(id.length - 1); // => "1"

This gets the characters starting at id.length - 5 and, since the second argument for .substr() is omitted, continues to the end of the string.

You can also use the .slice() method as others have pointed out below.

If you're simply looking to find the characters after the underscore, you could use this:

var tabId = id.split("_").pop(); // => "Tabs1"

This splits the string into an array on the underscore and then "pops" the last element off the array (which is the string you want).

Answer from Jamon Holmgren on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substring
String.prototype.substring() - JavaScript | MDN
The following example uses the substring() method and length property to extract the last characters of a particular string.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › lastIndexOf
String.prototype.lastIndexOf() - JavaScript | MDN
The method returns the index of the last occurrence of the specified substring at a position less than or equal to position, which defaults to Infinity. If position is greater than the length of the calling string, the method searches the entire string.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-the-last-character-of-a-string-in-javascript
JavaScript - How To Get The Last Caracter of a String? - GeeksforGeeks
To get the last character, you pass the index str.length - 1. ... The slice() method extracts a portion of the string. By passing -1 as an argument, you can extract the last character. ... A negative index in slice() counts from the end of the string. ... The substr() method extracts a substring starting from a specified position...
Published   July 11, 2025
🌐
CoreUI
coreui.io › blog › how-to-remove-the-last-character-from-a-string-in-javascript
How to Remove the Last Character from a String in JavaScript · CoreUI
June 23, 2024 - In this example, substring(0, str.length - 1) removes the last character by using the length of the string minus one as the end index.
🌐
W3Schools
w3schools.com › jsref › jsref_substr.asp
JavaScript String substr() Method
To extract characters from the end of the string, use a negative start position. The substr() method is removed (deprecated) in the latest JavaScript standard.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › remove-last-character
How to Remove the Last Character from a String in JavaScript - Mastering JS
Using /.$/ as the regular expression argument matches the last character of the string, so .replace(/.$/, '') replaces the last character of the string with an empty string. let str = 'Masteringjs.ioF'; str.substring(0, str.length - 1); // ...
🌐
W3Schools
w3schools.com › jsref › jsref_substring.asp
JavaScript String substring() Method
The substring() method extracts characters from start to end (exclusive).
🌐
TecAdmin
tecadmin.net › remove-last-character-from-string-in-javascript
2 Methods to Remove Last Character from String in JavaScript – TecAdmin
April 26, 2025 - In this tutorial, you have learned about removing the last character of a sting in JavaScript. We used substring() and slice() functions to alter a string.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-get-the-last-character-of-a-string-in-javascript
JavaScript – How To Get The Last Caracter of a String? | GeeksforGeeks
To get the last character, you pass the index str.length - 1. ... The slice() method extracts a portion of the string. By passing -1 as an argument, you can extract the last character. ... A negative index in slice() counts from the end of the string. ... The substr() method extracts a substring starting from a specified position...
Published   November 26, 2024
🌐
W3docs
w3docs.com › javascript
How to Get the Last Characters of a String
There are several methods used to get the last character of a string. In this tutorial you can find the simple solution for your case. You can use the Javascript string method .substr() combined with the length property.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-the-last-n-characters-of-a-string-in-javascript
JavaScript - How to Get the Last N Characters of a String? - GeeksforGeeks
July 23, 2025 - The slice() method is the most commonly used approach for extracting the last N characters, thanks to its simplicity and support for negative indices. ... The substring() method calculates the starting index based on the string's length.
🌐
Delft Stack
delftstack.com › home › howto › javascript › get last character of a string in javascript
How to Get Last Character of a String in JavaScript | Delft Stack
February 2, 2024 - Both the functions accept two parameters, the start index and the end index. They differ in their behavior as slice(-1) gives the last character of the string. Hence, it resembles substr() for getting the last character of the string.
🌐
Tutorial Reference
tutorialreference.com › javascript › examples › faq › javascript-how-to-get-the-substring-after-the-last-occurrence-of-a-character
How to Get the Substring After the Last Occurrence of a Character in JavaScript | Tutorial Reference
... function getAfterLast(str, char) { // Find the index of the last occurrence of the character const lastIndex = str.lastIndexOf(char); // Slice the string from the character after the last occurrence to the end return str.slice(lastIndex + 1); } // Example Usage: const filePath = ...
🌐
Joshtronic
joshtronic.com › 2018 › 11 › 12 › the-most-efficient-way-to-check-the-last-character-of-a-string-with-javascript
The most efficient way to check the last character of a string with JavaScript - Joshtronic
To test things out, I headed over to [jsperf.com][jsperf] and setup a handful of test cases to see how my go to of str.slice() stacked up against some other ways to grab the last character of a string. ... // length - 1 someString[someString.length - 1] === 'Z'; someString.substr(someString.length - 1) === 'Z'; someString.substring(someString.length - 1) === 'Z';
🌐
Stack Abuse
stackabuse.com › bytes › trim-the-last-n-characters-from-a-string-in-javascript
Trim the Last N Characters from a String in JavaScript
August 21, 2023 - The String.substring() method returns a new string that starts from a specified index and ends before a second specified index. We can use this method to trim the last N characters from a string.
🌐
W3Schools
w3schools.com › jsref › jsref_slice_string.asp
JavaScript String slice() Method
The substring() Method · string.slice(start, end) From position 3 to 8: let result = text.slice(3, 8); Try it Yourself » · Only the first character: let result = text.slice(0, 1); Try it Yourself » · Only the last character: let result = text.slice(-1); Try it Yourself » · The whole string: let result = text.slice(0); Try it Yourself » · JavaScript Strings ·
🌐
DEV Community
dev.to › bybydev › how-to-remove-last-character-from-string-in-javascript-2ghf
How to remove last character from string in JavaScript - DEV Community
May 4, 2024 - The substring(0, str.length - 1) method removes the last character because str.length - 1 is the last index of the string.
🌐
Coding Beauty
codingbeautydev.com › home › posts › how to get the last n characters of a string in javascript
How to Get the Last N Characters of a String in JavaScript - Coding Beauty
June 24, 2022 - const str = 'Coding Beauty'; // -3 is negative, uses 0 instead const notLast3 = str.substring(-3); console.log(notLast3); // Coding Beauty · A captivating guide to the subtle caveats and lesser-known parts of JavaScript.