Home >Web Front-end >JS Tutorial >Two ways to implement trim() function in Javascript_javascript skills
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:
Call in prototype mode, that is, in the form of obj.trim(). This method is simple and widely used. It is defined as follows:
Option 2:
Call 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: