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

String.prototype.trim() β€” trailing 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() β€” Trailing Whitespace

.trim() also removes spaces at the end of a string.

Challenge: Implement cleanTrailing(str) that removes trailing whitespace.

cleanTrailing('hello   ') // β†’ 'hello'
πŸ’‘ Hints (1)
  • β€’ `trim()` removes whitespace from the end as well as the start.