3 examples of 'javascript remove last character' in JavaScript

Every line of 'javascript remove last character' 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}
85function removeEndsChar(str, char) {
86 if (typeof str !== 'string') return '';
87
88 return str.endsWith(char) ? str.slice(0, -1) : str;
89}

Related snippets