Description
The trim() method returns a string stripped of whitespace from both ends.
This method has the form:
string.trim()
Note: This method does not change the value of the string itself.
Examples
The following example shows the basic use of this method.
<script>
var s = " Hello from JavaScript ";
document.write("'" + s.trim() + "'");
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|
3.5 | 9.0 | 10.0 | 10.5 | 5.0 |
Version Information
This form was added in version: 1.8.1
Description
The trimLeft() method returns a string stripped of whitespace from both ends.
This method has the form:
string.trimLeft()
Note: This method does not change the value of the string itself.
Examples
The following example shows the basic use of this method.
<script>
var s = " Hello from JavaScript ";
document.write("'" + s.trimLeft() + "'");
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|
Version Information
This form was added in version: 1.8.1
Description
The trimRight() method returns a string stripped of whitespace from the right end of the string.
This method has the form:
string.trimRight()
Note: This method does not change the value of the string itself.
Examples
The following example shows the basic use of this method.
<script>
var s = " Hello from JavaScript ";
document.write("'" + s.trimRight() + "'");
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|
Version Information
This form was added in version: 1.8.1