For AI agents: the complete documentation index is available at /tc39-atlas/en/llms.txt, the full documentation bundle is available at /tc39-atlas/en/llms-full.txt, and this page is available as Markdown at /tc39-atlas/en/proposals/stage/4/proposal-string-left-right-trim.md.
  • English
  • String.prototype.{trimStart,trimEnd} S4

    Proposal details
    Proposal overview

    This proposal aims to standardize String.prototype.trimStart and trimEnd methods, which trim whitespace from the beginning or end of a string, respectively. It also introduces trimLeft and trimRight as aliases to ensure web compatibility, matching the naming pattern of padStart/padEnd.

    Note

    The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.

    String.prototype.trimStart / String.prototype.trimEnd

    ECMAScript proposal, specs, tests, and reference implementation for String.prototype.trimStart/trimEnd (plus trimLeft/trimRight).

    Stage 4

    This proposal is complete and already merged into ECMA262 specification. See the specification text here.

    Rationale

    ES5 standardized String.prototype.trim. All major engines have also implemented corresponding trimLeft and trimRight functions - without any standard specification. For consistency with padStart/padEnd we propose trimStart and trimEnd and trimLeft/trimRight as aliases required for web compatibility.

    Specification

    You can view the spec in ecmarkup or rendered as HTML.

    Naming / Aliasing

    For consistency with padStart/padEnd the standard functions will be trimStart and trimEnd, however for web compatilibity trimLeft will alias trimStart and trimRight will alias trimEnd. This means String.prototype.trimRight.name will change from "trimRight" to "trimEnd" in most engines. The spec author does not expect this to cause any breakage.

    Test262 Coverage

    PR open

    Status of This Proposal

    This initial proposal was drafted by @sebmarkbage and the updated spec was drafted by @evilpie with input from @ljharb.

    This proposal is currently at stage 4 of the process.

    Designated TC39 reviewers: Jordan Harband + Daniel Ehrenberg

    Implementations