简体   繁体   English

React Native中的Object.keys顺序

[英]Object.keys order in React Native

Is it safe to assume that calling Object.keys() on object always returns array in the same order? 可以安全地假设在对象上调用Object.keys()总是以相同的顺序返回数组吗? I mean it wasn't specified in JS until ES2015 but I'm not sure how it is exactly in React Native? 我的意思是直到ES2015才在JS中指定它,但是我不确定它在React Native中到底是什么?

Property keys are traversed in the following order: 按以下顺序遍历属性键:

First, the keys that are integer indices in ascending numeric order. 首先,键是升序数字索引的整数索引。

Then, all other string keys, in the order in which they were added to the object. 然后,所有其他字符串键(按它们添加到对象的顺序)。

Lastly, all symbol keys, in the order in which they were added to the object. 最后,所有符号键(按它们添加到对象的顺序)。

Many engines treat integer indices specially (even though they are still strings, at least as far as the ES6 spec is concerned). 许多引擎都特别对待整数索引(即使它们仍然是字符串,至少就ES6规范而言也是这样)。 Therefore, it makes sense to treat them as a separate category of keys. 因此,将它们视为键的单独类别是有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM