Example 1 — Official: Matching Prefix
Return true when the string begins with the target.
_.startsWith('abc', 'a');
// → true How It Works
- String.
abcbegins at index0. - Target. Looking for
a. - Match. First character is
a. - Result.
true.

Checks if string starts with the given target string. Part of Lodash String since 4.0.0 (stable — not deprecated).
Note: Comparison is case-sensitive. Use an optional position to begin the check at a later index (same idea as native String.prototype.startsWith).
Call _.startsWith. Start with this line.
_.startsWith([string=''], [target], [position=0]) | Call | What it does |
|---|---|
_.startsWith([string=''], [target], [position=0]) | Primary signature. |
_.startsWith(string) | Transform or inspect a string. |
Prefer import startsWith from "lodash/startsWith" when you want a smaller bundle.
_.startsWith([string=''], [target], [position=0]) | Parameter | Description |
|---|---|
| string | Optional. String to inspect; default '' |
| target | Optional. Prefix to match |
| position | Optional. Index to begin the check; default 0 |
| Return Value | Description |
|---|---|
| * | true or false |
Return true when the string begins with the target.
_.startsWith('abc', 'a');
// → true abc begins at index 0.a.a.true.Return false when the beginning differs.
_.startsWith('abc', 'b');
// → false 0 is a, not b.false.position if you meant to start later.Begin the check at index 1.
_.startsWith('abc', 'b', 1);
// → true b.b.b.true (would be false at position 0).Letter case must match exactly.
_.startsWith('Abc', 'a');
// → false
_.startsWith('Abc', 'A');
// → true A.A → false.true.toLowerCase() on both sides first.endsWithPrefix vs suffix checks on the same string.
_.startsWith('abc', 'a');
// → true
_.endsWith('abc', 'c');
// → true
_.startsWith('abc', 'c');
// → false true.true.a → false._.startsWith is a Lodash String helper since 4.0.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
Available in [email protected] full builds and the lodash/startsWith modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
Bottom line: Safe for production once Lodash 4+ is loaded. Prefer import startsWith from "lodash/startsWith" for smaller bundles. For modern browsers only, native String.prototype.startsWith is also fine.
Compile Lodash string templates with custom delimiters.
CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
10 people found this page helpful