Get the App
SLTechnology News&Howtos  ›  Development  › 

Is there a trim method for javascript?

Shulou Source: shulou.com Published: 2022-05-31 22:49:27 10月03日 Update

This article introduces the relevant knowledge of "whether there is a trim method in javascript". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

There is a trim method in javascript. Trim () is a string processing method built into javascript that removes the beginning and end of a string with the syntax "string.trim ()"; the spaces that can be deleted by the trim method include space characters, tabs, line feeds, carriage returns, and so on.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

There is a trim method in javascript.

The trim () method is used to remove the leading and trailing white space character of a string. The syntax is as follows:

String.trim ()

The trim () method removes the following white space characters:

"": normal space character

"\ t": tabs

"\ n": newline character

"\ r": carriage return

"\ 0": empty byte character

"\ x0B": vertical tab.

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

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

JavaScript version: ECMAScript 5

Return value: returns a string that removes leading and trailing spaces

Example:

Function f () {var str1 = `123`; console.log (str1); console.log (str1.trim ()); var str2 = `\ n23\ n4`; console.log (str2); console.log (str2.trim ());} f ()

This is the end of the content of "is there any trim method for javascript"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Methods characters strings whitespace blank characters tabs spaces tabs contents head and tail newline characters more knowledge space characters grammar original practical ordinary uncomfortable learned Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft vpn NVidia Apple Shulou Tech Info