Home  >  Article  >  Web Front-end  >  Javascript trim() function implementation

Javascript trim() function implementation

黄舟
黄舟Original
2016-12-13 15:46:481343browse

There are many places where we need to use trim in JavaScript, but JavaScript does not have an independent trim function or method to use, so we need to write a trim function ourselves to achieve our purpose.


Option 1:

Called in prototype mode, that is, obj.trim() form. This method is simple and widely used. It is defined as follows:




Option 2:

Called in tool mode, that is, in the form of trim(obj). This method can be used for special processing needs. The definition is as follows:


Usage examples are as follows:


The above is an example of Javascript trim() function implementation. For more related content, please pay attention to the PHP Chinese website (www. php.cn) other articles.

Statement:
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