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

String.prototype.trim() β€” leading spaces

πŸ“– 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()

str.trim() removes whitespace from both the start and end of a string.

Challenge: Implement trimStr(str) that trims whitespace from both ends.

trimStr('   hello') // β†’ 'hello'
πŸ’‘ Hints (1)
  • β€’ `trim()` removes all leading and trailing whitespace characters.