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

python - how we can use ajax() in views.py in django? -

matlab - Using loops to get multiple values into a cell -

python - Sequence Pattern recognition with Pybrain -