为什么这个新创建的对象按数字升序排列?

时间:2015-10-08 13:15:18

标签: javascript object

当我运行此代码时

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"}
}

我想知道为什么新对象的排列是按升序排列的,而不是按照之前的顺序返回。

0 个答案:

没有答案