--- title: Map.prototype.entries() slug: Web/JavaScript/Reference/Global_Objects/Map/entries tags: - Map translation_of: Web/JavaScript/Reference/Global_Objects/Map/entries ---
entries()
方法返回一个新的包含 [key, value]
对的 Iterator
对象,返回的迭代器的迭代顺序与 Map
对象的插入顺序相同。
{{EmbedInteractiveExample("pages/js/map-prototype-entries.html")}}
myMap.entries()
一个新的 {{jsxref("Map")}} 迭代器对象.
entries()
的使用var myMap = new Map(); myMap.set("0", "foo"); myMap.set(1, "bar"); myMap.set({}, "baz"); var mapIter = myMap.entries(); console.log(mapIter.next().value); // ["0", "foo"] console.log(mapIter.next().value); // [1, "bar"] console.log(mapIter.next().value); // [Object, "baz"]
Specification | Status | Comment |
---|---|---|
{{SpecName('ESDraft', '#sec-map.prototype.entries', 'Map.prototype.entries')}} | {{Spec2('ESDraft')}} | |
{{SpecName('ES2015', '#sec-map.prototype.entries', 'Map.prototype.entries')}} | {{Spec2('ES2015')}} | Initial definition. |
{{Compat("javascript.builtins.Map.entries")}}