String startsWith() and endsWith()
String.prototype.startsWith() は文字列が指定した部分文字列で始まるかを、endsWith() は終わるかを真偽値で返します。
概要
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 |
基本構文
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..
プレビュー全画面表示
実務での使いどころ
-
String startsWith() and endsWith() の活用
文字列が指定した部分文字列で始まるか・終わるかを判定するメソッド。
注意点
- 特になし。すべての主要ブラウザで安定して動作する。
アクセシビリティ
- JavaScript による動的更新時は、aria-live リージョンで変更をスクリーンリーダーに通知する。
参考リンク
Powered by web-features