js 获取多个字段的对象数组中的某一些字段重新组成一个新的数组

const arr = [
  { name: 'John', age: 30, gender: 'male' },
  { name: 'Mary', age: 25, gender: 'female' },
  { name: 'Peter', age: 40, gender: 'male' }
];

const newArr = arr.map(item => {
  return {
    name: item.name,
    age: item.age
  };
});

console.log(newArr);

//运行结果
// [
//   { name: 'John', age: 30 },
//   { name: 'Mary', age: 25 },
//   { name: 'Peter', age: 40 }
// ]

你可能感兴趣的:(JavaScript,javascript,前端)