Widely availableSupported across all major browsers. Safe to use in production.

Overview

The startsWith() and endsWith() methods of strings returns whether a search string appears at the beginning or end of the provided string.

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

URL ski-mu. check

start or inspect it.. with StartsWith Use, URL that https://.

PreviewFullscreen

classification with prefix.

ID etc. String that specific. prefix in start or check..

PreviewFullscreen

Use cases

  • Using String startsWith() and endsWith()

    The startsWith() and endsWith() methods of strings returns whether a search string appears at the beginning or end of the provided string.

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.

Powered by web-features