Changing the order of the Object keys…

后端 未结 11 2171
無奈伤痛
無奈伤痛 2020-11-27 07:21
var addObjectResponse = [{
    \'DateTimeTaken\': \'/Date(1301494335000-0400)/\',
    \'Weight\': 100909.090909091,
    \'Height\': 182.88,
    \'SPO2\': \'222.00000         


        
11条回答
  •  我在风中等你
    2020-11-27 08:14

    2020 Update

    The answer below was correct at time of writing in 2011. However, since ES6, enumeration order has been specified as part of the language. Here's a nice article summarising this: https://2ality.com/2015/10/property-traversal-order-es6.html

    Original answer

    Properties of an object in JavaScript do not have an order. There may appear to be an order in some browsers but the ECMAScript specification defines object property enumeration order as being implementation-specific so you should not assume one browser's behaviour will be the same as another's. Chrome, for example, does not use the same ordering as some other browsers: see this lengthy bug report for at least as much discussion of this issue as you could possibly want.

    If you need a specific order, use an array, or two arrays (one for keys and one for values).

提交回复
热议问题