JavaScript `for in` returning sorted items

Viewed 49

I'm curious, I noticed, while running a for in on an object with numeric keys. The items seem to be consistently returning sorted. Anyone able to explain why this is?

const thing = {
  "2": "any",
  "8": "thing",
  "3": "here",
  "7": "x",
  "6": "xx",
  "1": "xxx"
};

for (var item in thing) {
  console.log(item);
}

0 Answers
Related