Java has LinkedHashMap
but there doesn't seem to be a similar solution in JavaScript.
Basically, I want to be able to say
var map = {};
map['a'] = 1;
map['b'] = 2;
Then when I iterate over the map, they are always in [{a:1}, {b:2}...] order.
I believe JavaScript Map object can help you to solve this issue:
let myObject = new Map();
myObject.set('z', 33);
myObject.set('1', 100);
myObject.set('b', 3);
for (let [key, value] of myObject) {
console.log(key, value);
}
// z 33
// 1 100
// b 3
Also, please take into consideration that this is ES6 (ES2015) standard. Cheers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With