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/startswith | |
| 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/startswith')
| -rw-r--r-- | files/ja/web/javascript/reference/global_objects/string/startswith/index.html | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/string/startswith/index.html b/files/ja/web/javascript/reference/global_objects/string/startswith/index.html new file mode 100644 index 0000000000..b8c5c200eb --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/string/startswith/index.html @@ -0,0 +1,98 @@ +--- +title: String.prototype.startsWith() +slug: Web/JavaScript/Reference/Global_Objects/String/startsWith +tags: + - ECMAScript 2015 + - JavaScript + - Method + - Prototype + - Reference + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>startsWith()</code></strong> メソッドは文字列が引数で指定された文字列で始まるかを判定して <code>true</code> か <code>false</code> を返します。</span></p> + +<div>{{EmbedInteractiveExample("pages/js/string-startswith.html")}}</div> + +<p class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><var>str</var>.startsWith(<var>searchString</var>[, <var>position</var>])</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>searchString</var></code></dt> + <dd>文字列の先頭で検索される文字の集合です。</dd> + <dt><code><var>position</var></code> {{optional_inline}}</dt> + <dd><code><var>searchString</var></code> を検索し始めるこの文字列の中の位置です。既定値は <code>0</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="例">例</h2> + +<h3 id="Using_startsWith" name="Using_startsWith">startsWith() の使用</h3> + +<pre class="brush: js notranslate">//startswith +let str = 'To be, or not to be, that is the question.' + +console.log(str.startsWith('To be')) // true +console.log(str.startsWith('not to be')) // false +console.log(str.startsWith('not to be', 10)) // true +</pre> + +<h2 id="Polyfill" name="Polyfill">ポリフィル</h2> + +<p>このメソッドは ECMAScript 2015 で追加されました。すべてのJavaScriptの実装でまだ利用可能ではないかもしれません。しかしながら、次のコードで<code>String.prototype.startsWith()</code>をエミュレートできます。</p> + +<pre class="brush: js notranslate">if (!String.prototype.startsWith) { + Object.defineProperty(String.prototype, 'startsWith', { + value: function(search, rawPos) { + var pos = rawPos > 0 ? rawPos|0 : 0; + return this.substring(pos, pos + search.length) === search; + } + }); +} +</pre> + +<p>少々重いですがより強力 (ES2015に完全準拠) な互換実装を <a href="https://github.com/mathiasbynens/String.prototype.startsWith">Mathias Bynens が GitHub</a> で公開しています。</p> + +<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.startswith', 'String.prototype.startsWith')}}</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.startsWith")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("String.prototype.endsWith()")}}</li> + <li>{{jsxref("String.prototype.includes()")}}</li> + <li>{{jsxref("String.prototype.indexOf()")}}</li> + <li>{{jsxref("String.prototype.lastIndexOf()")}}</li> +</ul> |
