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
- JS native implementation Promise.all
- TypeScript error TS2345: Argument of type ‘String ‘is not assignable to parameter of type ‘string’
- Difference between contenttype and datatype in Ajax request of jquery
- ECMAScript arguments object
- Localstorage sets the expiration time.
- Using for in loop complex data types (object and array) in ES6
- package.json Scripts configuration environment variable distinguishes development environment from production environment
- JavaScript determines whether parentheses are paired.
- If the request parameter is formdata, use the Ajax operation
- JS uses onerror to automatically catch exceptions
- Vue: How to Fix “not displaying the holder in IE9 and below”
- How to Fix “HTTP 405 method not allowed” Error
- How to use Runtime.getRuntime().Exec()
- Openmv identifies two-dimensional code, color recognition and serial communication
- Golang: How to Read File All Content in one time
- Google browser plug-in JavaScript errors Notifier
- Bugly automatically upload script and report zip error: nothing to do! In xcode10
- H5 page left and right stretch content area
- Vue refreshes the current page (no flash screen will appear)