JS Built-ins
← String176 / 195
StringString.prototype.trimEndbeginner

String.prototype.trimEnd() β€” trailing spaces removed

πŸ“– Usage Example
'  hello  '.trimEnd()   // β†’ '  hello'
'text   '.trimEnd()    // β†’ 'text'
'hi'.trimEnd()         // β†’ 'hi'

Use trimEnd() to remove only trailing whitespace from the end of a string, leaving leading whitespace intact.

String.prototype.trimEnd()

str.trimEnd() removes whitespace from the end (right side) of a string only.

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

trimRight('hello   ') // β†’ 'hello'
πŸ’‘ Hints (1)
  • β€’ `trimEnd()` only removes whitespace at the end of the string.