Below is my code. I'm putting a number and it's double as key-value pairs into an object. I'm curious as to why it is ordering the result by #. As in why does the '13': 26 entry come before '21': 42, when 13 comes after 21 in the array? Thanks for any insight.
var array = [1,2,3,4,5,8,7,21,13];
var object = {};
for (var i = 0; i < array.length; i++){
object[array[i]] = double(array[i]);
}
function double(a){
return a*2;
}
console.log(object);
Here is what I get in my console:
{ '1': 2,
'2': 4,
'3': 6,
'4': 8,
'5': 10,
'7': 14,
'8': 16,
'13': 26,
'21': 42 }