testing the order of properties in javascript objects

1
2
"use strict";
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
When you insert properties into an object, and then iterate over that object (eg with a for .. in loop). In what order are the properties retrieved ? This experiment aims to find out.

Verdict:
======

There is no guarantee in the ECMA spec (ecma-262) about the order of object properties.
However, in Practice:
Firefox, Node, Edge, Chrome, IE11:
Properties with non-numeric keys are iterated in the order they were inserted,
Properties with numeric keys are sorted in ascending order (this includes "stringified" numbers eg "100" or '100')

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.