2024-07-18 15:36:32 +03:00
# endsWith
::: info
2024-08-10 11:38:07 +03:00
This function is only available in `es-toolkit/compat` for compatibility reasons. It either has alternative native JavaScript APIs or isn’ t fully optimized yet.
When imported from `es-toolkit/compat` , it behaves exactly like lodash and provides the same functionalities, as detailed [here ](../../../compatibility.md ).
2024-07-18 15:36:32 +03:00
:::
Checks if a string contains another string at the end of the string.
Checks if one string ends with another string. Optional position parameter to search up the this position.
## Signature
```typescript
function endsWith(str: string, target: string, position: number = 0): string;
```
### Parameters
- `str` (`string`): The string that will be searched.
- `target` (`string`): The string that it should contain at the end.
2024-08-25 15:57:59 +03:00
- `position` (`number`, optional): The position to search up to this character position.
2024-07-18 15:36:32 +03:00
### Returns
2024-08-25 15:57:59 +03:00
(`boolean`): Whether or not the `str` string ends with the `target` string
2024-07-18 15:36:32 +03:00
## Examples
```typescript
2024-09-26 04:53:52 +03:00
import { endsWith } from 'es-toolkit/compat';
2024-07-18 15:36:32 +03:00
2024-08-10 11:38:07 +03:00
endsWith('fooBar', 'foo'); // returns false
endsWith('fooBar', 'Bar'); // returns true
endsWith('fooBar', 'abcdef'); // returns false
endsWith('fooBar', 'foo', 3); // returns true
2024-07-18 15:36:32 +03:00
```