JavaScript文字列endsWith()
例
文字列が「world」で終わっているかどうかを確認します。
let text = "Hello world";
let result = text.endsWith("world");
let text = "Hello World";
let result = text.endsWith("world");
以下のその他の例。
定義と使用法
文字列が指定された文字列で終わる場合、メソッドendsWith()
は戻ります。true
それ以外の場合はを返しますfalse
。
このendsWith()
方法では大文字と小文字が区別されます。
startswith()
メソッドも参照してください。
構文
string.endsWith(searchvalue, length)
パラメーター
Parameter | Description |
searchvalue | Required. The string to search for. |
length | Optional. The length of the string to search. Default value is the length of the string. |
戻り値
タイプ | 説明 |
ブール値 | true 文字列が値で終わる場合、それ以外の場合はfalse 。 |
その他の例
文字列の最初の11文字が「world」で終わっているかどうかを確認します。
let text = "Hello world, welcome to the universe.";
text.endsWith("world", 11);
ブラウザのサポート
endsWith()
ECMAScript6(ES6)機能です。
ES6(JavaScript 2015)は、最新のすべてのブラウザーでサポートされています。
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
endsWith()
Internet Explorer 11(またはそれ以前)ではサポートされていません。