Can chrome be forced to iterate "string numeric" keys in the order in which they are stored

It seems that I have an interesting problem only in chrome (not in IE, FF). Given the following object:

var myObj = {
  "59" : "Hello",
  "52" : "and",
  "50" : "how",
  "31" : "are",
  "65" : "you"
};

Going through this object through a for loop spits out the contents in the following order:

for(var j in myObj) {  document.write(myObj[j] +', '); }

are, how, and, hello, you

All other major browsers give it in the correct order. Chrome treats keys as integers instead of strings. The problem is that I have a json data source that I cannot change, and I need to access the elements in the order in which they are in the object.

Can anyone suggest a way to do this in Google Chrome?

+3
source share
2 answers

for...in . :

A for...in (. , , , , -).

delete:

, ECMAScript , , , , ( , , ). Internet Explorer, delete , - , , , . , undefined, , - , , .

, - , ( , ), ..

+5

Source: https://habr.com/ru/post/1785320/


All Articles