String trimLeft() and trimRight()Limited availability
The trimLeft() and trimRight() methods of strings return a new string with whitespace removed from the beginning or end of the string. They're aliases for trimStart() and trimEnd().
Not yet supported in all major browsers — check the table and provide a fallback.
Discouraged: TC39 recommends using trimStart() and trimEnd() instead. The trimLeft() and trimRight() aliases are provided for compatibility with old code. Use instead: String trimStart() and trimEnd()
Browser support
DesktopChrome
1–3Not supported
4+Supportedsince Jan 25, 2010
Current: 155Edge
12+Supportedsince Jul 29, 2015
Current: 154Firefox
1–3Not supported
3.5+Supportedsince Jun 30, 2009
Current: 157Safari
1–4Not supported
5+Supportedsince Jun 7, 2010
Current: 27MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155Firefox Android
4+Supportedsince Mar 29, 2011
Current: 157Safari iOS
1–4Not supported
4.2+Supportedsince Nov 22, 2010
Current: 27How to use
Support is still inconsistent across browsers. Use feature detection and test carefully.
Example
Full syntax and examples are on MDN: trimStart.
Feature detection
JS · check before using
if ("trimLeft" in String || ("prototype" in String && "trimLeft" in String.prototype)) {
// String.trimLeft is available
}Documentation (MDN)
Specification
Sub-features
Support for each part of the feature (2). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| String.trimLeft | 4 | 12 | 3.5 | 5 | 18 | 4 | 4.2 |
| String.trimRight | 4 | 12 | 3.5 | 5 | 18 | 4 | 4.2 |