Hi I am working on JavaScript Object.keys()
. According to Mozilla, Object.keys()
return an array whose elements are strings and the ordering of the properties is the same as
that given by looping over the properties of the object manually. However, I did use Map
, instead
let hashmap = {
1000: 'M',
900: 'CM',
500: 'D',
400: 'CD',
100: 'C',
90 : 'XC',
50 : 'L',
40 : 'XL',
10 : 'X',
9 : 'IX',
5 : 'V',
4 : 'IV',
1 : 'I'
}
for (let key of Object.keys(hashmap)){
console.log(key);
}
console.log(Object.keys(hashmap));
return value is
Array ["1", "4", "5", "9", "10", "40", "50", "90", "100", "400", "500", "900", "1000"]
I supposed to get the Array in the reversed order. Can any one tell me the reason why it looks like this ? Also, when looping over the object, it did not follow the order as well. Thanks! What is the root cause.