Skip to main content Link Search Menu Expand Document (external link)

trimEnd() : Remove Trailing Whitespace


On this page

Summary

Remove trailing whitespace from the end of a string.

Signature

trimEnd(str)

Parameters

Parameter Type Required Description
str String Yes The string to trim

Returns

Type: String

The string with trailing whitespace removed.


Examples

Remove Trailing Spaces

<p>""</p>

Data:

doc.Params["model"] = new {
    text = "Hello World   "
};

Output:

<p>"Hello World"</p>

Clean Line Endings


  <p></p>

Data:

doc.Params["model"] = new {
    lines = new[] {
        "Line 1   ",
        "Line 2\t\t",
        "Line 3\n"
    }
};

Output:

<p>Line 1</p>
<p>Line 2</p>
<p>Line 3</p>

Preserve Leading Spaces

<pre></pre>

Data:

doc.Params["model"] = new {
    code = "    function test() {   "
};

Output:

<pre>    function test() {</pre>

Notes

  • Only removes whitespace from the end of string
  • Preserves leading whitespace
  • Removes spaces, tabs, newlines, carriage returns
  • Returns original string if no trailing whitespace
  • For both ends, use trim()
  • Does not modify the original value

See Also