javascript - How to get correct order of js object? -


I have a question about the JSObJ order:

When I define: / P>

  var objJSON = {}; ObjJSON [31] = '123'; ------------- (1) Ojjason [23] = '456'; ------------- (2)   

and alert the object:

  Warning (JSON.stringify (objJSON , Tap, 4));   

It shows:

  "{" 23 ":" 456 "," 31 ":" 123 "}" I would like to get the object inserted In order of: "{" 31 ":" 123 "," 23 ":" 456 "}"   

How to do this?

The properties of an object are not guaranteed if the key, value and status Important, I would instead suggest an array of objects:

  var x = []; X.push ({key: 23, value: '123'}); X.push ({key: 31; value: '456'}); JSON.stringify (x); // {{"key": 23, "value": "123"}, {"key": 31, "value": "456"}]    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -