Object fields sequence

前端 未结 3 853
星月不相逢
星月不相逢 2021-01-25 14:29

I have a JavaScript object written in javascript code as below:

var rtnStr = {\"000\":\"area000\",\"020\":\"area020\",\"030\":\"area030\",
              \"040\":         


        
3条回答
  •  忘了有多久
    2021-01-25 15:15

    JavaScript objects are unordered.

    If you want to output their properties in a sorted order then:

    1. Create an array
    2. Loop over the object, pushing the property names into the array
    3. Sort the array
    4. Loop over the array (and use the values to access the original object).

提交回复
热议问题