0

Consider the following.

var options = {'All':'All'}
options['123'] = '123';
options['456'] = '456';
console.log(options);

The output of the above is Object {123: "123", 456: "456", All: "All"}, however, that is not what I want, I want to keep it's order and output as Object {All: "All", 123: "123", 456: "456"}

Why the ordering is damaged and how to avoid it?

Example

panda
  • 1,344
  • 3
  • 14
  • 35
  • object's keys have, actually no order. ususally the initial order is created by the creation. – Nina Scholz Oct 27 '16 at 07:17
  • Check again. It is in good order, as you want: https://jsfiddle.net/cgbxbdqb/1/ When you expand the object, you can see the order is right. – vaso123 Oct 27 '16 at 07:18
  • 2
    see: http://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order – Sean W Oct 27 '16 at 07:19

0 Answers0