Iterate over jQuery JSON object in original order

前端 未结 4 1927
误落风尘
误落风尘 2021-01-04 09:13

I\'ve got some json data in a map object which is sorted by time. The key is an integer id and the value is an object which contains a timestamp. However when I try to ite

4条回答
  •  遥遥无期
    2021-01-04 09:37

    In firefox objects keep the order.. in chrome they don't. No idea about other browser but two different implementations already show that you cannot rely on it.

    If you need something ordered, use a list; if you need something with both non-numeric keys and a certain order, the easiest way would be using a list of [key, value] lists:

    [['abd', 'def'], ['ghi', 'jkl']]
    

提交回复
热议问题