Widely available すべての主要ブラウザで対応済み。安心して使用可能。

概要

String.prototype.startsWith() は文字列が指定した部分文字列で始まるかを、endsWith() は終わるかを真偽値で返します。

対応ブラウザ

機能 デスクトップ モバイル
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
41
12
17
9
36
9
ビルトインオブジェクト

startsWith() は String 値のメソッドで、文字列が引数で指定された文字列で始まるかを判定して true か false を返します。

41
12
17
9
36
9
1+対応 (バージョン) 未対応 注釈あり サブ機能の解説は MDN Web Docs (CC BY-SA 2.5)

基本構文

JAVASCRIPT
const filename = 'document.pdf';

filename.startsWith('doc');  // true
filename.endsWith('.pdf');   // true
filename.endsWith('.txt');   // false

ライブデモ

fileextendedchild. check

EndsWith Use, filename that specific. extendedchild in end or inspect it..

プレビュー全画面表示

URL ski-mu. check

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

プレビュー全画面表示

classification with prefix.

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

プレビュー全画面表示

実務での使いどころ

  • String startsWith() and endsWith() の活用

    文字列が指定した部分文字列で始まるか・終わるかを判定するメソッド。

注意点

  • 特になし。すべての主要ブラウザで安定して動作する。

アクセシビリティ

  • JavaScript による動的更新時は、aria-live リージョンで変更をスクリーンリーダーに通知する。

Powered by web-features