How javascript object is sorting itself in ascending order of keys?
I noticed it for the first time.
/* It does maintain a order. The order in which you inserts the value. And if it does not maintain any orders, please show me example, that will be really helpful to understand me the concepts.
Thanks in advance.
*/
var a = {"13" : "1", "15" : "2", "14" : "3", "12" : "4"};
console.log(JSON.stringify(a)); /* This is nothing to do with for loop */
for(let i in a) {
console.log(i + " = " + a[i]);
}
/* But the keys other than numbers are not sorting. */
var b = {"c" : "1", "a" : "2", "b" : "3", "d" : "4"};
for(let i in b) {
console.log(i + " = " + b[i]);
}
First object is sorted by itself. I am creating keys as string for both the objects. But the second object is not sorting.