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