On this page
String.trim
Prev: replaceAll | Up: String | Next: matchAll
Rel: String, String, RegExp & Intl Guide
Ref: MDN Web Docs — String.trim
Tags: #public #web #javascript #builtins #string #tier/core
Signature & Overview
str.trim() /* + trimStart(), trimEnd() */
Removes leading and trailing Unicode whitespace from str.
Notes & Pitfalls
- Returns a new string (strings are immutable): Also see
trimStart()andtrimEnd()for one-sided trimming.
Example
console.assert(" hello world\n".trim() === "hello world");
Linked from
Related notes
- tuts/javascript/builtins/String/matchAll Linked here; links to this page; shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/replaceAll Linked here; links to this page; shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String Linked here; links to this page; shared tags: #builtins, #javascript, #string, #web
- tuts/javascript/builtins/string_regexp_and_intl Linked here; shared tags: #builtins, #javascript, #web
- tuts/javascript/builtins/String/includes shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/slice shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/split shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/substr shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/Array/at shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/filter shared tags: #builtins, #javascript, #tier, #web