startsWith()
startsWith(
str,prefix,position?):boolean
Checks if a string starts with a given prefix.
DEPRECATED
Use string.startsWith() directly instead.
Parametersβ
str: string | null | undefinedβ
The string to check.
prefix: string | null | undefinedβ
The prefix to search for.
position?: number = 0β
The position to start searching from.
Returns: booleanβ
true if the string starts with the prefix, false otherwise.
See Alsoβ
Sinceβ
2.0.0
Also known asβ
startsWith (Lodash, es-toolkit, Remeda, Ramda, Effect) Β· β (Radashi, Modern Dash, Antfu)
Exampleβ
// β Deprecated approach
startsWith('hello world', 'hello'); // => true
startsWith('hello world', 'world', 6); // => true
// β
Recommended approach
'hello world'.startsWith('hello'); // => true
'hello world'.startsWith('world', 6); // => true
How it works?β
Checks if string starts with the given target.
Deprecated: Use string.startsWith() directly (ES2015).
Native Equivalentβ
// β startsWith('hello', 'he')
// β
'hello'.startsWith('he')
Use Casesβ
Check prefix πβ
Check if string starts with value.
'hello world'.startsWith('hello'); // true
Validate protocolβ
Check URL protocol.
const isSecure = url.startsWith('https://');