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