By the end of this tutorial, you’ll use Lodash’s _.startsWith() confidently in real JavaScript projects.
01
Core syntax
_.startsWith(s, target)
02
Boolean
true / false
03
Position arg
Search from offset
04
URL checks
http/https guard
05
Case rules
Sensitive by default
06
vs native
String.startsWith()
Fundamentals
What Is _.startsWith()?
_.startsWith() checks whether a string begins with a given prefix. It is ideal for input validation, filtering arrays of filenames, and guarding URL or protocol formats.
💡
Beginner tip
Use _.startsWith(url, 'https://') before fetching remote resources—quick protocol validation without regex.
Foundation
📝 Syntax
javascript
_.startsWith(string, target, [position=0])
Syntax Rules
string — The string to inspect.
target — Prefix substring to find at the start (from position).
position — Optional index to begin searching (default 0).
Return — Boolean true if prefix matches.
Case — Case-sensitive unless you normalize case first.
javascript
import startsWith from "lodash/startsWith";
const str = "Hello, world!";
const ok = startsWith(str, "Hello");
// -> true
Cheat Sheet
⚡ Quick Reference
Task
Code pattern
Result
Basic
_.startsWith(s, 'pre')
true/false
At position
_.startsWith(s, 'world', 7)
true at offset
Case insensitive
_.startsWith(_.toLower(s), 'hello')
Normalized
URL
_.startsWith(url, 'https://')
Protocol guard
Filter files
files.filter(f => _.startsWith(f, 'app'))
Prefix filter
Native
s.startsWith('pre')
ES2015 equivalent
Returns
boolean
true or false
Default pos
0
Start of string
Case
sensitive
Normalize if needed
Pair
endsWith
Suffix check
Reference
🧰 Parameters
stringRequired
Source string to test.
_.startsWith(path, '/')
targetRequired
Prefix to match at position.
'https://'
positionOptional
Index where match should begin (default 0).
_.startsWith(s, 'x', 2)
return valueBoolean
true when prefix matches from position.
-> true
Hands-On
Examples Gallery
Practical _.startsWith() patterns with sample output and interactive Try It Yourself labs.