0

This is my object:

const small = {
    'S': 'CS3',
    'D': 'EB3',
    'G': 'FS3',
    'H': 'AB3',
    'J': 'BB3',
    '2': 'CS4',
    '3': 'EB4',
    '5': 'FS4',
    '6': 'AB4',
    '7': 'BB4'
}

I am trying to get an array of keys, IN THE ORIGINAL ORDER, and neither Object.keys(small) nor (for const key in small) work, it keeps reordering the array with the integers first. How can I get an array of these keys in this order?

Perplexityy
  • 398
  • 1
  • 5
  • 18
  • 2
    You can't. Objects are inherently unordered. If you care about order, you should use an array of single key-value pairs instead. – Robin Zigmond Aug 06 '20 at 11:50
  • 3
    There are rules for how object property names are ordered, but they're not under your control. Numeric keys always come first. – Pointy Aug 06 '20 at 11:51
  • 1
    https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/ – CBroe Aug 06 '20 at 11:51

0 Answers0