📜  如何在javascript代码示例中使用for循环获取数组对象值中的值

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

代码示例5
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);