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://');