0
var json = {
    displayImage1: {
        object: "style1"
    },
    displayImage4: {
        object: "style2"
    },
    displayImage3: {
        object: "style3"
    }
};

is there any way I can arrange my object values by number? So it would be:

displayImage1
displayImage3
displayImage4
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Jung
  • 197
  • 1
  • 1
  • 10
  • 3
    Your question is rather moot as the properties of an object cannot be ordered. If you need this behaviour you would need to use an array of objects instead. – Rory McCrossan Dec 01 '15 at 14:25
  • do the names always follow that "convention" - means is the number displayed at the end anytime? – messerbill Dec 01 '15 at 14:27
  • An object is, [by definition](http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf), an *unordered* collection of properties. The fact that a box can have both a height and a width says nothing about the order in which it has height and size. A representation of the properties of an object can have an inherent order, however. `Object.keys(json)`, for instance, yields an array of strings, which can be sorted in any manner you like. Is this what you are requesting? – David Hedlund Dec 01 '15 at 14:36

0 Answers0