6 examples of 'how to remove last character from string in javascript' in JavaScript

Every line of 'how to remove last character from string in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
48deleteLastChar() {
49 var lastString = this.strings_.length - 1;
50 var last = this.strings_[lastString];
51 if (last) {
52 this.strings_[lastString] = last.slice(0, -1);
53 }
54}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

140function replaceLastCharacter(string, character) {
141 return string.slice(0, string.length - 1) + character;
142}
69function rmTrailingChar(str, c) {
70 if (str.slice(-1)[0] === c) return str.slice(0, -1);
71 else return str;
72}
67function removeCarriageReturns(string) {
68 alert(string);
69 return string.replace(/\n/g, "");
70}
85function removeEndsChar(str, char) {
86 if (typeof str !== 'string') return '';
87
88 return str.endsWith(char) ? str.slice(0, -1) : str;
89}
30function replaceAt(string, index, char) {
31 return string.substr(0, index) + char + string.substr(index + char.length);
32}

Related snippets