Lodash _.startsWith() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
String

Definition

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).

Syntax

Call _.startsWith. Start with this line.

Lodash
_.startsWith([string=''], [target], [position=0])
CallWhat 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.

Library declarations
Lodash
_.startsWith([string=''], [target], [position=0])

Parameters

ParameterDescription
stringOptional. String to inspect; default ''
targetOptional. Prefix to match
positionOptional. Index to begin the check; default 0

Return Value

Return ValueDescription
*true or false

Lodash Examples

Example 1 — Official: Matching Prefix

Return true when the string begins with the target.

Lodash
_.startsWith('abc', 'a');
// → true
Try It Yourself

How It Works

  1. String. abc begins at index 0.
  2. Target. Looking for a.
  3. Match. First character is a.
  4. Result. true.

Example 2 — Official: Non-Matching Prefix

Return false when the beginning differs.

Lodash
_.startsWith('abc', 'b');
// → false
Try It Yourself

How It Works

  1. Start. Index 0 is a, not b.
  2. No match. Prefix check fails.
  3. Result. false.
  4. Tip. Use position if you meant to start later.

Example 3 — Official: Position Offset

Begin the check at index 1.

Lodash
_.startsWith('abc', 'b', 1);
// → true
Try It Yourself

How It Works

  1. Position 1. Look at substring starting at b.
  2. Target. Still b.
  3. Match. That slice starts with b.
  4. Result. true (would be false at position 0).

Example 4 — Case-Sensitive

Letter case must match exactly.

Lodash
_.startsWith('Abc', 'a');
// → false

_.startsWith('Abc', 'A');
// → true
Try It Yourself

How It Works

  1. First char. String starts with A.
  2. Lowercase a. Does not equal A → false.
  3. Uppercase A. Matches → true.
  4. Insensitive. Compare toLowerCase() on both sides first.

Example 5 — vs endsWith

Prefix vs suffix checks on the same string.

Lodash
_.startsWith('abc', 'a');
// → true

_.endsWith('abc', 'c');
// → true

_.startsWith('abc', 'c');
// → false
Try It Yourself

How It Works

  1. startsWith a. Beginning matches → true.
  2. endsWith c. Ending matches → true.
  3. startsWith c. Beginning is a → false.
  4. Pick. Protocols / schemes → startsWith; extensions → endsWith.

Browser & Runtime Support

_.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.

✓ Stable · Lodash 4.0.0+

_.startsWith()

Available in [email protected] full builds and the lodash/startsWith modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.0+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.startsWith Lodash 4.0.0+

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.

Frequently Asked Questions

_.startsWith([string=''], [target], [position=0]) returns true if string begins with target (from an optional position). Official: _.startsWith('abc', 'a') → true.
Yes. _.startsWith('Abc', 'a') is false. Lowercase both sides first if you need a case-insensitive check.
It is the index where the search begins. Official: _.startsWith('abc', 'b', 1) → true because the check starts at index 1.
Behavior matches modern native startsWith closely. Lodash coerces nullish string inputs safely (e.g. _.startsWith(null, 'a') → false).
startsWith checks the beginning; endsWith checks the end. Both return a boolean.
Use import startsWith from "lodash/startsWith" or require("lodash/startsWith") for tree-shaking. Full build: import _ from "lodash" then _.startsWith.

Next: _.template()

Compile Lodash string templates with custom delimiters.

_.template() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful