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/array/values | |
| 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/array/values')
| -rw-r--r-- | files/ja/web/javascript/reference/global_objects/array/values/index.html | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/array/values/index.html b/files/ja/web/javascript/reference/global_objects/array/values/index.html new file mode 100644 index 0000000000..29b90252b6 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/array/values/index.html @@ -0,0 +1,122 @@ +--- +title: Array.prototype.values() +slug: Web/JavaScript/Reference/Global_Objects/Array/values +tags: + - Array + - ECMAScript2015 + - Iterator + - JavaScript + - Method + - Prototype + - メソッド + - 反復子 +translation_of: Web/JavaScript/Reference/Global_Objects/Array/values +--- +<div>{{JSRef}}</div> + +<p><strong><code>values()</code></strong> メソッドは、配列の各インデックスの値を含む新しい <strong><code>Array Iterator</code></strong> オブジェクトを返します。</p> + +<div>{{EmbedInteractiveExample("pages/js/array-values.html")}}</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><var>arr</var>.values()</pre> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>新しい {{jsxref("Array")}} iterator オブジェクトです。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Iteration_using_for...of_loop" name="Iteration_using_for...of_loop">for...of ループを用いた反復処理</h3> + +<pre class="brush: js notranslate">var arr = ['a', 'b', 'c', 'd', 'e']; +var iterator = arr.values(); + +for (let letter of iterator) { + console.log(letter); +} //"a" "b" "c" "d" "e" +</pre> + +<p><strong>Array.prototype.values</strong> は <strong>Array.prototype[Symbol.iterator]</strong> の既定の実装です。</p> + +<pre class="notranslate">Array.prototype.values === Array.prototype[Symbol.iterator] //true</pre> + +<h3 id="Iteration_using_.next" name="Iteration_using_.next">.next() を使用した反復処理</h3> + +<pre class="brush: js notranslate">var arr = ['a', 'b', 'c', 'd', 'e']; +var iterator = arr.values(); +iterator.next(); // Object { value: "a", done: false } +iterator.next().value; // "b" +iterator.next()["value"]; // "c" +iterator.next(); // Object { value: "d", done: false } +iterator.next(); // Object { value: "e", done: false } +iterator.next(); // Object { value: undefined, done: true } +iteraror.next().value; // undefined </pre> + +<div class="blockIndicator warning"> +<p>一度だけの使用: 配列の反復子オブジェクトは一度だけの使用またはテンポラリオブジェクトです</p> +</div> + +<p>例:</p> + +<pre class="brush: js notranslate">var arr = ['a', 'b', 'c', 'd', 'e']; + var iterator = arr.values(); + for (let letter of iterator) { + console.log(letter); +} //"a" "b" "c" "d" "e" +for (let letter of iterator) { +console.log(letter); +} // undefined +</pre> + +<p><strong>理由:</strong> <code>next().done=true</code> または <code>currentIndex>length</code> が <code>for..of</code> の終了条件だからです。<a href="/ja/docs/Web/JavaScript/Reference/Iteration_protocols">反復処理プロトコル</a>を参照して下さい。</p> + +<p><strong>値</strong>: 配列の反復子オブジェクトには値が格納されません。その代わりに、その作成に使用された配列のアドレスが格納されるので、その配列に格納されている値に依存します。</p> + +<pre class="brush: js notranslate">var arr = ['a', 'b', 'c', 'd', 'e']; +var iterator = arr.values(); +console.log(iterator); // Array Iterator { } +iterator.next().value; // "a" +arr[1]='n'; +iterator.next().value; // "n" +</pre> + +<div class="blockIndicator note"> +<p>配列内の値が変化した場合は、配列の反復子オブジェクトの値も変化します。</p> +</div> + +<p class="hidden"><strong>TODO</strong>: please write about why we need it, use cases.</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-array.prototype.values', 'Array.prototype.values')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<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.Array.values")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Array.prototype.keys()")}}</li> + <li>{{jsxref("Array.prototype.entries()")}}</li> + <li>{{jsxref("Array.prototype.forEach()")}}</li> + <li>{{jsxref("Array.prototype.every()")}}</li> + <li>{{jsxref("Array.prototype.some()")}}</li> +</ul> |
