From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/string/endswith/index.html | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/string/endswith/index.html (limited to 'files/ja/web/javascript/reference/global_objects/string/endswith/index.html') diff --git a/files/ja/web/javascript/reference/global_objects/string/endswith/index.html b/files/ja/web/javascript/reference/global_objects/string/endswith/index.html new file mode 100644 index 0000000000..3020f5c05c --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/string/endswith/index.html @@ -0,0 +1,94 @@ +--- +title: String.prototype.endsWith() +slug: Web/JavaScript/Reference/Global_Objects/String/endsWith +tags: + - JavaScript + - Method + - Prototype + - Reference + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/endsWith +--- +
{{JSRef}}
+ +

endsWith() メソッドは文字列が引数で指定された文字列で終わるかを判定して truefalse を返します。

+ +
{{EmbedInteractiveExample("pages/js/string-endswith.html")}}
+ + + +

構文

+ +
str.endsWith(searchString[, length])
+ +

引数

+ +
+
searchString
+
str の末尾で検索される文字の集合です。
+
length {{optional_inline}}
+
指定された場合、 str の長さとして使用されます。既定値は str.length です。
+
+ +

返値

+ +

文字列が指定された文字列で終わる場合は true、それ以外の場合は false です。

+ +

解説

+ +

文字列が特定の文字列で終わるかどうかを判断できます。このメソッドでは (英文字の) 大文字・小文字は区別されます。

+ +

+ +

endsWith() の使用

+ +
let str = 'To be, or not to be, that is the question.'
+
+console.log(str.endsWith('question.'))  // true
+console.log(str.endsWith('to be'))      // false
+console.log(str.endsWith('to be', 19))  // true
+
+ +

ポリフィル

+ +

このメソッドは ECMAScript 6 で追加されました。すべての JavaScript の実装でまだ利用可能ではないかもしれません。しかしながら、次のコードで String.prototype.endsWith() をエミュレートできます。

+ +
if (!String.prototype.endsWith) {
+  String.prototype.endsWith = function(search, this_len) {
+    if (this_len === undefined || this_len > this.length) {
+      this_len = this.length;
+    }
+    return this.substring(this_len - search.length, this_len) === search;
+  };
+}
+
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-string.prototype.endswith', 'String.prototype.endsWith')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.builtins.String.endsWith")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf