JS Built-ins
← String175 / 195
StringString.prototype.trimbeginner

String.prototype.trim() β€” tabs and newlines

πŸ“– Usage Example
'  hello  '.trim()      // β†’ 'hello'
'
 text 	'.trim()   // β†’ 'text'
'no spaces'.trim()   // β†’ 'no spaces'

Use trim() to remove all leading and trailing whitespace characters from a string.

String.prototype.trim() β€” Tabs and Newlines

.trim() removes all whitespace characters: spaces, tabs (\t), and newlines (\n).

Challenge: Implement trimAll(str) that removes all surrounding whitespace including tabs and newlines.

trimAll('\t hello \n') // β†’ 'hello'
πŸ’‘ Hints (1)
  • β€’ `trim()` removes all Unicode whitespace characters, including `\t`, `\n`, `\r`, and spaces.