当我运行此代码时
var OrderPeople = function (people) {
var byAge = {};
people.forEach(function (person) {
byAge[person.age] = person;
});
return byAge;
};
console.log(OrderPeople([ { age: 83, name: 'joel' },
{ age: 46, name: 'roger' },
{ age: 99, name: 'vinny' },
{ age: 26, name: 'don' },
{ age: 74, name: 'brendan' } ]));
我得到以下输出
{
26: {age: 26, name: "don"}
46: {age: 46, name: "roger"}
74: {age: 74, name: "brendan"}
83: {age: 83, name: "joel"}
99: {age: 99, name: "vinny"}
}
我想知道为什么新对象的排列是按升序排列的,而不是按照之前的顺序返回。