简体   繁体   English

Javascript 函数 Object.keys 无法正常工作

[英]Javascript function Object.keys not working correct

Javascript function Object.keys seems to not work correct: Javascript 函数 Object.keys 似乎无法正常工作:

public availableParents: any[] = [];

availableParents[abbreviation] = textField;

the field availableParents is sent to a function.字段 availableParents 被发送到一个函数。

Then in debug mode I dispay the variable ... and also an Object.keys on the variable :然后在调试模式下,我显示变量......以及变量上的 Object.keys :

Immediate window :立即窗口:

?dataSource
[]
    __proto__: []
    ALG: "ALG | Alg"
    length: 0
    SC-1-1: "Scene"

? Object.keys(dataSource)
[SC-1-1,ALG]
    __proto__: []
    length: 2
    [0]: "SC-1-1"
    [1]: "ALG"

I would have expected that Object.keys would return (?) :我原以为 Object.keys 会返回 (?) :

[ALG,SC-1-1]
    __proto__: []
    length: 2
    [0]: "ALG"
    [1]: "SC-1-1"

You can't order an object.你不能订购一个对象。 The keys are stocked in (pseudo-)random order.密钥以(伪)随机顺序存放。

If you want to keep track of which key/value you put in first, you better have to use arrays.如果您想跟踪首先放入的键/值,则最好使用数组。

If you just want to have an alphabetical order, use sort() method on your Object.keys resulting list如果您只想按字母顺序排列,请在Object.keys结果列表上使用sort()方法

Good luck祝你好运

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

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