endsWith()
endsWith(
str,suffix,position?):boolean
Checks if a string ends with a given suffix.
DEPRECATED
Use string.endsWith() directly instead.
Parametersโ
str: string | null | undefinedโ
The string to check.
suffix: string | null | undefinedโ
The suffix to search for.
position?: numberโ
The position to search up to.
Returns: booleanโ
true if the string ends with the suffix, false otherwise.
See Alsoโ
Sinceโ
2.0.0
Also known asโ
endsWith (Lodash, es-toolkit, Remeda, Ramda, Effect) ยท โ (Radashi, Modern Dash, Antfu)
Exampleโ
// โ Deprecated approach
endsWith('hello world', 'world'); // => true
endsWith('hello world', 'lo', 5); // => true
// โ
Recommended approach
'hello world'.endsWith('world'); // => true
'hello world'.endsWith('lo', 5); // => true
How it works?โ
Checks if string ends with the given target.
Deprecated: Use string.endsWith() directly (ES2015).
Native Equivalentโ
// โ endsWith('hello', 'lo')
// โ
'hello'.endsWith('lo')
Use Casesโ
Check suffix ๐โ
Check if string ends with value.
'hello world'.endsWith('world'); // true
Validate extensionโ
Check file extension.
const isTypeScript = filename.endsWith('.ts');