var a = ['a1', 'b2', 'd4', 'c3'];
var dict = {};
for(var i=0; i<a.length; ++i) {
dict[(a[i].match(/\d+/)[0])] = a[i];
}
console.log(dict);
for(var i=0; i<a.length; ++i) {
dict[a[i]] = a[i].match(/\d+/)[0];
}
console.log(dict);
In the first case, where keys are numbers, we have output with dictionary keys sorted.
But in second case, where keys are not numbers, we have output with a dictionary keys in the order they were added!
Is this some hidden feature, I mean is it reliable every time?