Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use trim in javascript

Shulou Source: shulou.com Published: 2022-06-02 20:58:19 09月27日 Update

This article mainly introduces how to use trim in javascript, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The javascript trim method is used to remove the leading and trailing blank characters of a string, its syntax is "string.trim ()", and the return value is the string that removes the leading and trailing spaces.

This article operating environment: Windows7 system, javascript1.8.5 version, DELL G3 computer

What is the use of javascript trim?

JavaScript trim () method:

The trim () method is used to remove the leading and trailing white space characters of a string, which include: spaces, tabs tab, newline characters, and so on.

The trim () method does not change the original string.

The trim () method does not apply to null, undefined, Number types.

Grammar

String.trim ()

Return value

String, which returns the string that removes the leading and trailing spaces.

Example

If your browser does not support the trim () method, you can use regular expressions to do so:

Function myTrim (x) {return x.replace (/ ^\ s + |\ ssteps Universalgm law');} function myFunction () {var str = myTrim ("Runoob"); alert (str);}

Output result:

Runoob thank you for reading this article carefully. I hope the article "how to use trim in javascript" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Tags: Methods characters strings head and tail white space blank characters articles spaces grammar support primitive discomfort value interest tabs and at the same time examples newline characters more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Tech Info Shulou Technology Xiaomi Redmi