coderef

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: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1–3Not supported
3.5+Supportedsince Jun 30, 2009
Current: 157
Safari
1–4Not supported
5+Supportedsince Jun 7, 2010
Current: 27
MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155
Firefox Android
4+Supportedsince Mar 29, 2011
Current: 157
Safari iOS
1–4Not supported
4.2+Supportedsince Nov 22, 2010
Current: 27

How 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
}

Sub-features

Support for each part of the feature (2). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
String.trimLeft4123.551844.2
String.trimRight4123.551844.2