0
  let jsonobj = {
    name: "Ironman",
    power: "vibranium",
    student: "spiderman",
    identity: "Tony stark"
  }

  console.log(jsonobj)

The output for this which I got is:

{name: 'Ironman', power: 'vibranium', student: 'spiderman', identity: 'Tony stark'}
identity: "Tony stark"
name: "Ironman"
power: "vibranium"
student: "spiderman"

I was expecting it in the same order as how I gave it in the input, not in a sorted manner.

Dmitriy Popov
  • 2,150
  • 3
  • 25
  • 34
blogger10
  • 23
  • 5
  • 3
    That's a browser thing - when you iterate an objects keys (`for..in`, `Object.keys()`, `Reflect.ownKeys`, etc...) you'll find that string keys are iterated in insertion order – Nick Parsons Jun 29 '23 at 11:00
  • I meant those keys were sorted in alphabetical order... which are displayed outside the curly braces – blogger10 Jun 29 '23 at 11:05

0 Answers0