📜  遍历对象数组 javascript 代码示例

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

代码示例9
// Sort an array

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);