Skip to content

Commit

Permalink
Object.entries() order does depend on how an object is defined (#6937)
Browse files Browse the repository at this point in the history
See also mdn/interactive-examples#1868 for the comment in the code
example.
  • Loading branch information
Andreu Botella authored Jul 15, 2021
1 parent 9f6b9eb commit 1656238
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@

<p>The <code><strong>Object.entries()</strong></code> method returns an array of a given
object's own enumerable string-keyed property
<code>[<var>key</var>, <var>value</var>]</code> pairs, in the same order as that
provided by a {{jsxref("Statements/for...in", "for...in")}} loop. (The only important
difference is that a <code>for...in</code> loop enumerates properties in the prototype
<code>[<var>key</var>, <var>value</var>]</code> pairs. This is the same as iterating
with a {{jsxref("Statements/for...in", "for...in")}} loop, except that a
<code>for...in</code> loop enumerates properties in the prototype
chain as well). </p>

<p>The order of the array returned by <code><strong>Object.entries()</strong></code> does
not depend on how an object is defined. If there is a need for certain ordering, then
<p>The order of the array returned by <code><strong>Object.entries()</strong></code> is
the same as that provided by a {{jsxref("Statements/for...in", "for...in")}} loop. If
there is a need for different ordering, then
the array should be sorted first, like
<code>Object.entries(obj).sort((a, b) =&gt; b[0].localeCompare(a[0]));</code>.</p>

Expand Down

0 comments on commit 1656238

Please sign in to comment.