Here is an approach using str.slice(0, -n). Where n is the number of characters you want to truncate.

var str = 1437203995000;
str = str.toString();
console.log("Original data: ",str);
str = str.slice(0, -3);
str = parseInt(str);
console.log("After truncate: ",str);

Answer from Hari Das on Stack Overflow
🌐
Dirask
dirask.com › posts › JavaScript-remove-last-3-characters-from-string-8pV22p
JavaScript - remove last 3 characters from string
By using .{0,3}$ pattern we match any 3 characters (up to 3 characters) that are located at the end of the string. // ONLINE-RUNNER:browser; var text = 'abcde'; var substring = text.replace(/.{0,3}$/, ''); console.log(substring); // ab · JavaScript - how to chop off last 3 chars from string?
Discussions

Removing last 3 characters from a string? (SQLite)
Is there a way to just cut the last three digits off? SELECT SUBSTR(yourcolumn, 1, LENGTH(yourcolumn)-3 ) FROM ... More on reddit.com
🌐 r/SQL
6
6
April 10, 2023
Replace last character in string
Just depends how complex you want to make it. You could technically do it all in the pipeline: 'East1','West2' | ForEach-Object { if ($_[-1] -eq '1') { ($_.substring(0,$_.length-1) + '2') } else { ($_.substring(0,$_.length-1) + '1') } } East2 West1 More on reddit.com
🌐 r/PowerShell
10
4
January 16, 2020
People also ask

What is the easiest way to remove last 3 characters in JavaScript?
A: The easiest way can be using the slice() method, which is straightforward and efficient for this use case.
🌐
sqlpey.com
sqlpey.com › javascript › remove-last-3-characters
Top 4 Ways to Remove Last 3 Characters from a String or Number ...
Can I apply these methods to other data types?
A: Yes, while the examples focus on numbers and strings, similar string manipulation techniques can be adapted for any data type that can be represented as a string.
🌐
sqlpey.com
sqlpey.com › javascript › remove-last-3-characters
Top 4 Ways to Remove Last 3 Characters from a String or Number ...
🌐
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, replace(/,$/, '') removes the last character only if it’s a comma. Although less common, the substr() method can also remove the last character.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-remove-first-and-last-characters-from-a-string
JavaScript- Remove Last Characters from JS String - GeeksforGeeks
July 23, 2025 - The slice() method returns a part of a string by specifying the start and end indices. To remove the last character, we slice the string from the start (index 0) to the second-to-last character.
🌐
Scaler
scaler.com › home › topics › remove last character from string in javascript
Remove the Last Character from a String in JavaScript - Scaler Topics
May 4, 2023 - Use the replace() Method The replace() function in javascript can also be used the remove the last character from the string. The replace() function takes second parameter as the whole string and the first parameter is for matching string and instructing the number of characters needed to be ...
🌐
sebhastian
sebhastian.com › javascript-remove-last-n-characters-from-string
JavaScript Remove Last N Characters From A String | sebhastian
September 15, 2023 - Some browsers might have removed this function completely. To prevent breaking your web application, never use this method again. To remove the last N characters from a JavaScript string, use either the slice() or substring() method.
Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-remove-last-n-characters-from-string
Remove the last N Characters from a String in JavaScript | bobbyhadz
March 1, 2024 - Copied!const str = 'bobbyhadz.com'; // ✅ Remove the last 3 characters from a string const removeLast3 = str.slice(0, -3); console.log(removeLast3); // 👉️ bobbyhadz. // ------------------------------------------------- // ✅ Same as above ...
🌐
sqlpey
sqlpey.com › javascript › remove-last-3-characters
Top 4 Ways to Remove Last 3 Characters from a String or Number in JavaScript
November 23, 2024 - You might want to truncate it to remove the last three digits, making it easier to read or manipulate. Below are several approaches you can use to achieve this. One simple approach is to utilize the slice() method. This method allows you to specify the starting and ending indices to extract ...
🌐
YouTube
youtube.com › watch
How to Remove the Last 2,3,4, N Characters from a String in JavaScript - YouTube
To remove the last 2, 3, 4, and N characters from a string in JavaScript using different methods by w3school. Here are some examples to remove the last 2,3,4...
Published: December 16, 2023
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › remove-last-character
How to Remove the Last Character from a String in JavaScript - Mastering JS
November 12, 2021 - 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); // Masteringjs.io str.substr(0, str.length - 1); // Masteringjs.io str.replace(/.$/, ''); // Masteringjs.io · With replace(), you can specify if the last character should be removed depending on what it is with a regular expression.
🌐
TecAdmin
tecadmin.net › remove-last-character-from-string-in-javascript
2 Methods to Remove Last Character from String in JavaScript – TecAdmin
April 26, 2025 - Use the slice() function to remove the last character from any string in JavaScript. This function extracts a part of any string and return as new string.
🌐
Medium
medium.com › @onlinemsr › how-to-remove-the-last-character-from-a-string-in-javascript-3d1c238d1669
How to Remove the Last Character from a String in JavaScript | by Raja MSR | Medium
February 15, 2024 - Removing the last character from a string can be tricky, as there are different methods and scenarios to consider. ... By the end of this blog post, you will have a better understanding of how to use JavaScript to remove the last character from a string, and how to apply this skill to various situations.
🌐
Medium
medium.com › @ryan_forrester_ › javascript-remove-last-character-from-string-fc1cabdf2722
Javascript Remove Last Character From String | by ryan | Medium
September 10, 2024 - For strings with only one character, removing the last character will result in an empty string. This behavior should be acceptable for most applications, but it’s important to be aware of it. ... Strings in JavaScript are immutable, meaning the original string is not modified by operations like slice() or substring().
🌐
Coderslang
learn.coderslang.com › 0179-how-to-remove-the-last-n-characters-from-a-javascript-string
How to remove the last n characters from a JavaScript string
January 24, 2022 - The slice function is a convenient way to remove the last n characters from a JavaScript string. It accepts 2 parameters. The first one is the starting point. The second one is the number of items to remove from a string.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-program-to-remove-last-character-from-the-string
JavaScript Program to Remove Last Character from the String | GeeksforGeeks
June 17, 2024 - In this approach, we will use substring() method for removing last character of string. The string.substring() is an inbuilt function in JavaScript that is used to return the part of the given string from the start index to the end index.
Top answer
1 of 5
1
No worries @StewartF, ·   · Try this... I think we're there now. · To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos. · Thanks, Robbie · var encQBySN = "sys_id=79ec46839742c2d032ea7a200153af1a"; //Adjust accordingly for testing. Comment out when happy with the results · var computersCount = 0; //Used for sanity check when testing · var computersNameCPU = 0; · var computersGR = new GlideRecord('cmdb_ci_vmware_instance'); //Change this table as required for specific CI class or type · //computersGR.addEncodedQuery(encQ); · computersGR.addEncodedQuery(encQBySN); · computersGR.setLimit(10); //Adjust this number or comment it out completely to run against all records · computersGR.query(); · while(computersGR.next()){ · computersCount++; · var computerName = computersGR.getValue('name'); · var computerSysID = computersGR.getValue('sys_id'); · var endsWith = computerName.endsWith("CPU"); //Note - endWith method is case sensitive so 'cpu' will not match · if(endsWith){ //Only interested in computers ending with CPU · computersNameCPU++; · gs.print('computerName: ' + computerName + ' Sys ID:' + computerSysID); //Comment when running as a bulk action against all Computers · var newComputerName = computerName.substring(0,computerName.length-3); · gs.print('TRIMMED computerName: ' + newComputerName + ' Sys ID:' + computerSysID); · computersGR.setValue('name', newComputerName); · //computersGR.update() //Comment and uncomment as appropriate · } · } · gs.print('Total computers checked: ' + computersCount) //Verify expected reults · gs.print('Total computers ending in CPU: ' + computersCount) //Verify expected reults · View solution in original post
2 of 5
0
Hi @StewartF, ·   · This is easily achieved using the following script. · Best practice tip - Create this as a 'Fix Script' so it can be reused (if required) but most importantly can be rolled back if required. - See below Screenshot and syntax. · Note - If you need to roll back any of the changes, navigate to the rollbacks by typing 'sys_rollback_context.LIST' into the nav menu. · PLEASE MAKE SURE YOU TEST AND ADAPT THE QUERY IN A LOWER ENVIRONMENT (NON PROD) BEFORE EXECUTING · To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos. · Thanks, Robbie · //var encQ = "operational_statusIN1,2,3,4,5" //An encoded query if you want to filter for certain records · var encQBySN = "serial_numberINVVM-370-F60616-KN,DVS-360-J56754-QH"; //Adjust accordingly for testing. Comment out when happy with the results · var count = 0; //Used for sanity check when testing · var computersGR = new GlideRecord('cmdb_ci_computer'); //Change this table as required for specific CI class or type · //computersGR.addEncodedQuery(encQ); · computersGR.addEncodedQuery(encQBySN); · //computersGR.setLimit(10); · computersGR.query(); · while(computersGR.next()){ · count++; · var computerName = computersGR.getValue('name'); · var computerSN = computersGR.getValue('serial_number'); · if(computerName.length > 20){ · gs.print('computerName: ' + computerName + ' Serial number:' + computerSN); //Comment when running as a bulk action against all Computers · var newComputerName = computerName.substring(0,computerName.length-3); · computersGR.setValue('name', newComputerName); · computersGR.update() //Comment and uncomment as appropriate · } · } · gs.print('Total computers: ' + count) //Verify expected reults
🌐
Coderslang
learn.coderslang.com › 0030-javascript-remove-last-character-from-a-string
JavaScript, remove last character from a string - Coderslang
February 14, 2021 - const base = 'javascript, remove last char!' const s = base.substring(0, base.length - 1); console.log(s); // javascript, remove last char · Take a note, though, that if you pass a negative number into substring as a second argument, you’ll get an empty string
🌐
Flexiple
flexiple.com › javascript › javascript-remove-last-character-from-string
JavaScript Remove Last Character from String - Flexiple
June 6, 2024 - Removing the last character from a string in JavaScript is a straightforward task that can be accomplished using various methods, such as slice(), substring(), substr(), regular expressions, and split()/join(). Each method has its use cases, ...