3 examples of 'js remove last character' in JavaScript

Every line of 'js 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
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}
85function removeEndsChar(str, char) {
86 if (typeof str !== 'string') return '';
87
88 return str.endsWith(char) ? str.slice(0, -1) : str;
89}
69function rmTrailingChar(str, c) {
70 if (str.slice(-1)[0] === c) return str.slice(0, -1);
71 else return str;
72}

Related snippets