From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- .../global_objects/array/entries/index.html | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 files/zh-tw/web/javascript/reference/global_objects/array/entries/index.html (limited to 'files/zh-tw/web/javascript/reference/global_objects/array/entries') diff --git a/files/zh-tw/web/javascript/reference/global_objects/array/entries/index.html b/files/zh-tw/web/javascript/reference/global_objects/array/entries/index.html new file mode 100644 index 0000000000..80c3f33e1f --- /dev/null +++ b/files/zh-tw/web/javascript/reference/global_objects/array/entries/index.html @@ -0,0 +1,86 @@ +--- +title: Array.prototype.entries() +slug: Web/JavaScript/Reference/Global_Objects/Array/entries +tags: + - Array + - ECMAScript6 + - Iterator + - JavaScript + - Method + - Prototype + - 迭代器 + - 陣列 +translation_of: Web/JavaScript/Reference/Global_Objects/Array/entries +--- +
{{JSRef}}
+ +

entries() 方法會回傳一個包含陣列中每一個索引之鍵值對(key/value pairs)的新陣列迭代器(Array Iterator)物件。

+ +
{{EmbedInteractiveExample("pages/js/array-entries.html")}}
+ + + +

語法

+ +
a.entries()
+ +

回傳值

+ +

一個新的 {{jsxref("Array")}} 迭代器物件。

+ +

範例

+ +

使用 for…of 進行迭代

+ +
var a = ['a', 'b', 'c'];
+var iterator = a.entries();
+
+for (let e of iterator) {
+  console.log(e);
+}
+// [0, 'a']
+// [1, 'b']
+// [2, 'c']
+
+ +

規範

+ + + + + + + + + + + + + + + + + + + +
規格狀態備註
{{SpecName('ES2015', '#sec-array.prototype.entries', 'Array.prototype.entries')}}{{Spec2('ES2015')}}首次定義。
{{SpecName('ESDraft', '#sec-array.prototype.entries', 'Array.prototype.entries')}}{{Spec2('ESDraft')}} 
+ +

瀏覽器相容性

+ +
+ + +

{{Compat("javascript.builtins.Array.entries")}}

+
+ +

參見

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