es-toolkit/docs/reference/compat/string/endsWith.md
D-Sketon f7853a80c1
docs: fix import (#599)
* docs: fix import

* docs: fix import
2024-09-26 10:53:52 +09:00

39 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# endsWith
::: info
This function is only available in `es-toolkit/compat` for compatibility reasons. It either has alternative native JavaScript APIs or isnt fully optimized yet.
When imported from `es-toolkit/compat`, it behaves exactly like lodash and provides the same functionalities, as detailed [here](../../../compatibility.md).
:::
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.
- `position` (`number`, optional): The position to search up to this character position.
### Returns
(`boolean`): Whether or not the `str` string ends with the `target` string
## Examples
```typescript
import { endsWith } from 'es-toolkit/compat';
endsWith('fooBar', 'foo'); // returns false
endsWith('fooBar', 'Bar'); // returns true
endsWith('fooBar', 'abcdef'); // returns false
endsWith('fooBar', 'foo', 3); // returns true
```