Javascript function Object.keys seems to not work correct:
public availableParents: any[] = [];
availableParents[abbreviation] = textField;
the field availableParents is sent to a function.
Then in debug mode I dispay the variable ... and also an Object.keys on the variable :
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 (?) :
[ALG,SC-1-1]
__proto__: []
length: 2
[0]: "ALG"
[1]: "SC-1-1"
1 Answer 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
Good luck
answered Jan 15, 2020 at 15:03
Benoit Messiaen
2241 silver badge5 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
availableParents = empty list... I've never felt so sad reading code...