How to stop json Data for automatic sorting in Google Chrome?

JQuery + Rails 4

<script> var jsonData = { "81404": "Object", "81408": "Object", "81416": "Object", "80387": "Object", "73952": "Object", "74697": "Object", "81411": "Object", "74700": "Object" }; console.log(jsonData); </script> 

Mozilla exit (right and expected)

 Object { 81404="Object", 81408="Object", 81416="Object", 80387="Object", 73952="Object", 74697="Object", 81411="Object", 74700="Object"} 

Chrome output (wrong ???)

 Object {73952: "Object", 74697: "Object", 74700: "Object", 80387: "Object", 81404: "Object", 81408: "Object", 81411: "Object", 81416: "Object"} 

How to fix this problem with automatic sorting in Chrome any suggestion suggestion ,,

I use this data to filter this order.

+6
source share
1 answer

Your data is not an array. He has no internal order. These are simply properties of the object.

From this link

4.3.3 Object
An object is a member of type Object. This is an unordered set of properties , each of which contains a primitive value, object, or function.

Put them in the array property of the JSON object if order is important (or just use an array!).

eg. sort of:

 var jsonData = {data: [ {"81404": "Object"}, {"81408": "Object"}, {"81416": "Object"}, {"80387": "Object"}, {"73952": "Object"}, {"74697": "Object"}, {"81411": "Object"}, {"74700": "Object"}] }; console.log(jsonData); 

or just for list

 console.log(jsonData.data); 

It would be helpful to explain what you are doing with the data, so any example is more applicable.

+5
source

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


All Articles