There is trim method in javascript. trim() is a string processing method built into JavaScript, which is used to remove whitespace characters at the beginning and end of a string. The syntax is "string.trim()"; the whitespace characters that the trim method can delete include spaces and tabs. character, line feed character, carriage return character, etc.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
There is a trim method in javascript.
The trim() method is used to remove leading and trailing whitespace characters from a string. The syntax is as follows:
string.trim()
trim() method can remove the following whitespace characters:
" ": ordinary space characters;
"\t": tab character;
"\n": line feed character;
"\r": carriage return character;
"\0": null byte character;
"\x0B": vertical tab character.
The trim() method does not change the original string.
trim() method is not applicable to null, undefined, Number types.
JavaScript version: | ECMAScript 5 |
---|
Return value: Returns removing leading and trailing spaces String
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();
[Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of Does javascript have a trim method?. For more information, please follow other related articles on the PHP Chinese website!