String trimStart() and trimEnd()
The trimStart() and trimEnd() methods of strings return a new string with whitespace removed from the beginning or end of the string.
Overview
The trimStart() and trimEnd() methods of strings return a new string with whitespace removed from the beginning or end of the string.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 66 | 79 | 61 | 12 | 66 | 12 | |
| Built-in object | ||||||
| The trimStart() method of String values removes whitespace from the beginning of this string and returns a new string, without modifying the original string. trimLeft() is an alias of this method. | 66 | 79 | 61 | 12 | 66 | 12 |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 1 item(s)
Implementation note
- Previously available under a different name: trimRight (4)
Notes 1 item(s)
Implementation note
- Previously available under a different name: trimRight (12)
Notes 1 item(s)
Implementation note
- Previously available under a different name: trimRight (3.5)
Notes 1 item(s)
Implementation note
- Previously available under a different name: trimRight (18)
Notes 1 item(s)
Implementation note
- Previously available under a different name: trimLeft (4)
Notes 1 item(s)
Implementation note
- Previously available under a different name: trimLeft (12)
Notes 1 item(s)
Implementation note
- Previously available under a different name: trimLeft (3.5)
Notes 1 item(s)
Implementation note
- Previously available under a different name: trimLeft (18)
Syntax
JAVASCRIPT
' hello '.trimStart(); // 'hello '
' hello '.trimEnd(); // ' hello'
' hello '.trim(); // 'hello' Live demo
Inputform. Format
yu-za- that inputvalue. beforeafter to existsnot-main spe-s batch in getexclude..
PreviewFullscreen
Use cases
Using String trimStart() and trimEnd()
The trimStart() and trimEnd() methods of strings return a new string with whitespace removed from the beginning or end of the string.
Cautions
- No specific concerns. Stable across all major browsers.
Accessibility
- When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.
Related links
Powered by web-features