📜  javascript foreach 对象数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:33.478000             🧑  作者: Mango

代码示例6
const people = [
  { name: "John", age: 21 },
  { name: "Peter", age: 31 },
  { name: "Andrew", age: 29 },
  { name: "Thomas", age: 25 }
];

let sortByAge = people.sort(function (p1, p2) {
  return p1.age - p2.age;
});

console.log(sortByAge);