diff options
Diffstat (limited to 'files/ja/web/javascript')
| -rw-r--r-- | files/ja/web/javascript/reference/global_objects/string/lastindexof/index.html | 83 | 
1 files changed, 38 insertions, 45 deletions
| diff --git a/files/ja/web/javascript/reference/global_objects/string/lastindexof/index.html b/files/ja/web/javascript/reference/global_objects/string/lastindexof/index.html index 73c8f7f823..90c80353c3 100644 --- a/files/ja/web/javascript/reference/global_objects/string/lastindexof/index.html +++ b/files/ja/web/javascript/reference/global_objects/string/lastindexof/index.html @@ -2,44 +2,47 @@  title: String.prototype.lastIndexOf()  slug: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf  tags: -  - JavaScript -  - Method -  - Prototype -  - Reference -  - String -  - lastIndexOf +- JavaScript +- Method +- Prototype +- Reference +- String +- lastIndexOf +browser-compat: javascript.builtins.String.lastIndexOf  translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf  ---  <div>{{JSRef}}</div> -<p><span class="seoSummary"><strong><code>lastIndexOf()</code></strong> メソッドは、呼び出した {{jsxref("String")}} オブジェクトの中で、 <code>fromIndex</code> から前方向に検索を始め、指定された値が最後に現れたインデックスを返します。値が見つからない場合は <code>-1</code> を返します。</span></p> +<p><strong><code>lastIndexOf()</code></strong> メソッドは、呼び出した {{jsxref("String")}} オブジェクトの中で、 <code>fromIndex</code> から前方向に検索を始め、指定された値が最後に現れたインデックスを返します。値が見つからない場合は <code>-1</code> を返します。</p>  <div>{{EmbedInteractiveExample("pages/js/string-lastindexof.html", "shorter")}}</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> +<h2 id="Syntax">構文</h2> -<pre class="syntaxbox notranslate"><var>str</var>.lastIndexOf(<var>searchValue</var>[, <var>fromIndex</var>])</pre> +<pre class="brush: js"> +lastIndexOf(searchValue) +lastIndexOf(searchValue, fromIndex) +</pre> -<h3 id="Parameters" name="Parameters">引数</h3> +<h3 id="Parameters">引数</h3>  <dl> - <dt><code><var>searchValue</var></code></dt> - <dd>検索する値を表す文字列です。 <code><var>searchValue</var></code> が空文字列であった場合は、 <code><var>fromIndex</var></code> を返します。 - </dd><dt><code><var>fromIndex</var></code> {{optional_inline}}</dt> - <dd>比較の先頭とみなされる文字列の最後の文字の位置です。既定値は <code>+Infinity</code> です。 <code><var>fromIndex</var> >= <var>str</var>.length</code> の場合、文字列全体が検索されます。 <code><var>fromIndex</var> < 0</code> の場合は、 <code>0</code> の場合と同じ動作になります。 -</dd></dl> +  <dt><code><var>searchValue</var></code></dt> +  <dd>検索する値を表す文字列です。 <code><var>searchValue</var></code> が空文字列であった場合は、 <code><var>fromIndex</var></code> を返します。</dd> +  <dt><code><var>fromIndex</var></code> {{optional_inline}}</dt> +  <dd>比較の先頭とみなされる文字列の最後の文字の位置です。既定値は <code>+Infinity</code> です。 <code><var>fromIndex</var> >= <var>str</var>.length</code> の場合、文字列全体が検索されます。 <code><var>fromIndex</var> < 0</code> の場合は、 <code>0</code> の場合と同じ動作になります。</dd> +</dl> -<h3 id="Return_value" name="Return_value">返値</h3> +<h3 id="Return_value">返値</h3>  <p><code><var>searchValue</var></code> が最後に出現した位置です。見つからなかった場合は、 <code>-1</code> になります。</p> -<h2 id="Description" name="Description">解説</h2> +<h2 id="Description">解説</h2>  <p>文字列における文字は左から右にインデックス化されます。一番最初の文字の位置は <code>0</code> で、一番最後の文字は <code><var>str</var>.length - 1</code> です。</p> -<pre class="brush: js notranslate">'canal'.lastIndexOf('a');     // returns 3 +<pre class="brush: js">'canal'.lastIndexOf('a');     // 3 を返す  'canal'.lastIndexOf('a', 2);  // 1 を返す  'canal'.lastIndexOf('a', 0);  // -1 を返す  'canal'.lastIndexOf('x');     // -1 を返す @@ -53,20 +56,20 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf  <p><strong>注:</strong> <code>'abab'.lastIndexOf('ab', 2)</code> は <code>2</code> を返し、 <code>0</code> にはなりません。 <code><var>fromIndex</var></code> は検索の開始位置を制約するものだからです。</p>  </div> -<h3 id="Case-sensitivity" name="Case-sensitivity">大文字と小文字の区別</h3> +<h3 id="Case-sensitivity">大文字と小文字の区別</h3>  <p><code>lastIndexOf()</code> メソッドは大文字と小文字を区別します。例えば、以下の式は <code>-1</code> を返します。</p> -<pre class="brush: js notranslate">'Blue Whale, Killer Whale'.lastIndexOf('blue'); // -1 を返す +<pre class="brush: js">'Blue Whale, Killer Whale'.lastIndexOf('blue'); // -1 を返す  </pre> -<h2 id="Examples" name="Examples">例</h2> +<h2 id="Examples">例</h2> -<h3 id="Using_indexOf_and_lastIndexOf" name="Using_indexOf_and_lastIndexOf">indexOf() と lastIndexOf() の使用</h3> +<h3 id="Using_indexOf_and_lastIndexOf">indexOf() と lastIndexOf() の使用</h3>  <p>以下の例は、 {{jsxref("String.prototype.indexOf()", "indexOf()")}} と <code>lastIndexOf()</code> を使用して文字列 "<code>Brave new world</code>" の中の値の位置を示します。</p> -<pre class="brush: js notranslate">let anyString = 'Brave new world'; +<pre class="brush: js">let anyString = 'Brave new world';  console.log('先頭から見て最初に w が出現する位置: ' + anyString.indexOf('w'));  // 8 と出力 @@ -78,31 +81,21 @@ console.log('末尾から見た "new" の位置: ' + anyString.lastIndexOf('new'  // 6 と出力  </pre> -<h2 id="Specifications" name="Specifications">仕様書</h2> +<h2 id="Specifications">仕様書</h2> + +{{Specifications}} -<table class="standard-table"> - <thead> -  <tr> -   <th scope="col">仕様書</th> -  </tr> - </thead> - <tbody> -  <tr> -   <td>{{SpecName('ESDraft', '#sec-string.prototype.lastindexof', 'String.prototype.lastIndexOf')}}</td> -  </tr> - </tbody> -</table> +<h2 id="Browser_compatibility">ブラウザーの互換性</h2> -<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> -<p>{{Compat("javascript.builtins.String.lastIndexOf")}}</p> +<p>{{Compat}}</p> -<h2 id="See_also" name="See_also">関連情報</h2> +<h2 id="See_also">関連情報</h2>  <ul> - <li>{{jsxref("String.prototype.charAt()")}}</li> - <li>{{jsxref("String.prototype.indexOf()")}}</li> - <li>{{jsxref("String.prototype.split()")}}</li> - <li>{{jsxref("Array.prototype.indexOf()")}}</li> - <li>{{jsxref("Array.prototype.lastIndexOf()")}}</li> +  <li>{{jsxref("String.prototype.charAt()")}}</li> +  <li>{{jsxref("String.prototype.indexOf()")}}</li> +  <li>{{jsxref("String.prototype.split()")}}</li> +  <li>{{jsxref("Array.prototype.indexOf()")}}</li> +  <li>{{jsxref("Array.prototype.lastIndexOf()")}}</li>  </ul> | 
