Home > Web Front-end > JS Tutorial > body text

javascript trim space removal function implementation code

不言
Release: 2018-05-04 15:32:42
Original
1693 people have browsed it

This article mainly introduces the implementation code of the javascript trim space removal function. It has a certain reference value. Now I share it with you. Friends in need can refer to it

Remove the spaces at both ends of the string. You can easily use trim, ltrim or rtrim in vbscript, but there are no these three built-in methods in js and you need to write them manually. The following implementation method uses regular expressions, which is very efficient, and adds these three methods to the built-in methods of the String object.


 
 

 
 

 
 

 
Copy after login

[Ctrl A to select all Note: If you need to introduce external Js, you need to refresh it before executing]


Write as a function It can be like this:

Copy code The code is as follows:

Copy after login


The above is the detailed content of javascript trim space removal function implementation code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!