String startsWith() and endsWith()
The endsWith() method of String values determines whether a string ends with the characters of this string, returning true or false as appropriate.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 41 | 12 | 17 | 9 | 36 | 9 | |
| Built-in object | ||||||
| The startsWith() method of String values determines whether this string begins with the characters of a specified string, returning true or false as appropriate. | 41 | 12 | 17 | 9 | 36 | 9 |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
JAVASCRIPT
const filename = 'document.pdf';
filename.startsWith('doc'); // true
filename.endsWith('.pdf'); // true
filename.endsWith('.txt'); // false Live demo
fileextendedchild. check
EndsWith Use, filename that specific. extendedchild in end or inspect it..
PreviewFullscreen
classification with prefix.
ID etc. String that specific. prefix in start or check..
PreviewFullscreen
Use cases
-
Using String startsWith() and endsWith()
The endsWith() method of String values determines whether a string ends with the characters of this string, returning true or false as appropriate.
Cautions
- No specific concerns. Stable across all major browsers.
Accessibility
- When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.