JS Built-ins
← String181 / 195
StringString.prototype.trimStartbeginner

String.prototype.trimStart() β€” leading spaces removed

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

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

String.prototype.trimStart()

str.trimStart() removes whitespace from the start (left side) of a string only.

Challenge: Implement trimLeft(str) that removes leading whitespace.

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