By the end of this tutorial, you’ll use Lodash’s _.trimStart() confidently in real string workflows.
01
Core Syntax
Call _.trimStart(string, [chars]).
02
Leading Only
Removes characters from the start, not the end.
03
Custom Chars
Optional charset instead of whitespace.
04
Form Input
Strip accidental leading spaces from user text.
05
Alias
_.trimLeft is identical.
06
Production Tips
Normalize file contents and imported rows.
Fundamentals
What Is _.trimStart()?
_.trimStart() removes characters from the beginning of a string while leaving the end untouched. Pair it with _.trimEnd() for one-sided cleanup, or use _.trim() when both sides need attention.
💡
Beginner tip
Think of _.trimStart(input) as “remove spaces the user accidentally typed before their answer, but keep trailing content as-is.”
Foundation
📝 Syntax
javascript
_.trimStart(string, [chars])
Syntax Rules
string — The input string.
chars — Optional characters to remove from the start (default: whitespace).
Return value — New string without leading matched characters.
Alias — _.trimLeft is the same function.
javascript
import trimStart from "lodash/trimStart";
const raw = " Hello, World!";
const result = trimStart(raw);
// -> "Hello, World!"
Cheat Sheet
⚡ Quick Reference
Task
Code pattern
Result
Whitespace
_.trimStart(str)
Leading spaces gone
Custom
_.trimStart(str, "-")
Strip leading hyphens
Alias
_.trimLeft(str)
Same function
File read
_.trimStart(contents)
BOM / indent cleanup
Both ends
_.trim(str)
Full edge trim
Native
str.trimStart()
Built-in equivalent
Mutates?
No
Returns new string
Side
Start only
Leading chars
Alias
trimLeft
Same API
Native
trimStart()
ES2019+
Reference
🧰 Parameters
stringRequired
String to process.
_.trimStart(input)
charsOptional
Character set for leading removal. Default is whitespace.
_.trimStart(code, "#")
return valueNew string
Copy without leading matched characters.
const clean = _.trimStart(raw)
trailing keptPreserved
End of string is never modified by trimStart.
// trailing spaces stay
Hands-On
Examples Gallery
Practical _.trimStart() patterns with copy-ready code and interactive Try It Yourself labs.
_.trimStart() cleans leading whitespace and custom characters without touching the end of your string. Use it for form input, imported rows, and file preprocessing when only the beginning needs normalization.