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

String.prototype.trimEnd() β€” leading spaces preserved

πŸ“– 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() β€” Leading Spaces Preserved

trimEnd() does NOT touch the leading whitespace β€” only trailing whitespace is removed.

Challenge: Implement trimEndOnly(str) that removes trailing but preserves leading whitespace.

trimEndOnly('  hello  ') // β†’ '  hello'
πŸ’‘ Hints (1)
  • β€’ `trimEnd()` is asymmetric β€” it only affects the right side of the string.