The first uses the replace method of the string
var str = "hello-world-"
// \S non-blank character $ ending {1} Match a
str = str.replace(/\S{1}$/, '');
console.log(str);
The second way is to use string interception and there are three APIs for string interception and I’m only going to talk about two of them
var str = "hello-world-"
console.log(str.slice(0, -1));
console.log(str.substring(0, str.length - 1));
The final output is hello-world
Watch me keep my front-end knowledge updated
Read More:
- JS to determine whether the string contains a character
- Solution to some map files in JS folder after Vue packaging (remove the map. JS file)
- node.js yarn Error: SyntaxError: Unexpected string [How to Solve]
- [Solved] To install it, you can run: npm install –save core-js/modules/es.error.cause.js
- request.js?b775:101 Uncaught (in promise) Error: Failed to convert value of type ‘java.lang.String’ to required type ‘java.lang.Long’;
- TypeScript error TS2345: Argument of type ‘String ‘is not assignable to parameter of type ‘string’
- Node.js Error: Cannot find module express [How to Solve]
- Solution to build error in Vue project (error in static/JS)/vendor.xxxxx.js from UglifyJs)
- Node.js Error: Error: Cannot find module ‘express‘ [How to Solve]
- [Solved] Nuxt Import qrcodejs2.js / QRCode.js Error: document is not defined
- JS: How to Solve split, join, toString Use error
- [Solved] it only responds to error and does not enter success after AJAX is successfully processed
- [Solved] webpack Package Error: ERROR in multi ./src/main.js ./dist/bundle.js Module not found: Error: Can‘t resolv
- Failed to execute ‘setRequestHeader’ on ‘XMLHttpRequest’: String contains non ISO-8859-1 code point.
- JS uses onerror to automatically catch exceptions
- vue.config.js build Package UglifyJsPlugin to clear console and print console.log Error: `warnings` is not a supported option
- Error: Computed property “menuList” was assigned to but it has no setter.
- [Solved] JS Error: Uncaught SyntaxError: Illegal return statement
- Golang: How to determine structure whether it is empty
- The solution to the failure of HTML introducing external JS