entries() 方法回傳一個 Iterator 物件,其包含著一個由插入順序排序,Set 物件中每個元素的 [value, value] 陣列。儘管對 Set 物件來說沒有像 Map 一樣的 key 概念,為了確保這個 API 運作的與 Map 相似,每個 entry 都有同樣的值同時作為其 keyvalue ,因此回傳的是一個[value, value] 的陣列。

語法

mySet.entries()

回傳值

一個新的 Iterator 物件,包含著一個由插入順序排序,Set 物件中每個元素的 [value, value] 陣列。

範例

使用 entries()

var mySet = new Set();
mySet.add('foobar');
mySet.add(1);
mySet.add('baz');

var setIter = mySet.entries();

console.log(setIter.next().value); // ["foobar", "foobar"]
console.log(setIter.next().value); // [1, 1]
console.log(setIter.next().value); // ["baz", "baz"]

規範

規範 狀態
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Set.prototype.entries' in that specification.
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
The definition of 'Set.prototype.entries' in that specification.
Draft  

瀏覽器相容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
entriesChrome Full support 38Edge Full support 12Firefox Full support 24IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support 38Chrome Android Full support 38Edge Mobile Full support 12Firefox Android Full support 24Opera Android Full support 25Safari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12

Legend

Full support  
Full support
No support  
No support

另見

文件標籤與貢獻者

此頁面的貢獻者: hmysjiang
最近更新: hmysjiang,