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

String.prototype.trimEnd() β€” trailing newline

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

trimEnd() also removes trailing newlines and tabs.

Challenge: Implement stripNewline(str) that removes a trailing newline.

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