diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/javascript/reference/global_objects/string/endswith/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/string/endswith/index.html')
-rw-r--r-- | files/ja/web/javascript/reference/global_objects/string/endswith/index.html | 94 |
1 files changed, 94 insertions, 0 deletions
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 +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>endsWith()</code></strong> メソッドは文字列が引数で指定された文字列で終わるかを判定して <code>true</code> か <code>false</code> を返します。</span></p> + +<div>{{EmbedInteractiveExample("pages/js/string-endswith.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><var>str</var>.endsWith(<var>searchString</var>[, <var>length</var>])</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>searchString</var></code></dt> + <dd><code><var>str</var></code> の末尾で検索される文字の集合です。</dd> + <dt><code><var>length</var></code> {{optional_inline}}</dt> + <dd>指定された場合、 <code><var>str</var></code> の長さとして使用されます。既定値は <code><var>str</var>.length</code> です。</dd> +</dl> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>文字列が指定された文字列で終わる場合は <strong><code>true</code></strong>、それ以外の場合は <strong><code>false</code></strong> です。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p>文字列が特定の文字列で終わるかどうかを判断できます。このメソッドでは (英文字の) 大文字・小文字は区別されます。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_endsWith" name="Using_endsWith">endsWith() の使用</h3> + +<pre class="brush: js notranslate">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 +</pre> + +<h2 id="Polyfill" name="Polyfill">ポリフィル</h2> + +<p>このメソッドは ECMAScript 6 で追加されました。すべての JavaScript の実装でまだ利用可能ではないかもしれません。しかしながら、次のコードで <code>String.prototype.endsWith()</code> をエミュレートできます。</p> + +<pre class="brush: js notranslate">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; + }; +} +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ESDraft', '#sec-string.prototype.endswith', 'String.prototype.endsWith')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.String.endsWith")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("String.prototype.startsWith()")}}</li> + <li>{{jsxref("String.prototype.includes()")}}</li> + <li>{{jsxref("String.prototype.indexOf()")}}</li> + <li>{{jsxref("String.prototype.lastIndexOf()")}}</li> +</ul> |