将数组对象中的属性值取出并组成新的数组
let arr = [
{name: "张三", age: "1", sex: "男", grade: 11},
{name: "李四", age: "2", sex: "男", grade: 12},
{name: "王五", age: "3", sex: "男", grade: 13},
{name: "赵六", age: "4", sex: "男", grade: 16},
]
let res = arr.map((item,index) => {
return Object.assign({},{'name':item.name,'grade':item.grade})
})
console.log(res)
// 输出结果为 [{name: '张三', grade: 11},{name: '李四', grade: 12},{name: '王五', grade: 13}, {name: '赵六', grade: 16}]
标签:name,grade,age,JavaScript,sex,item,王五,几种,数据
From: https://www.cnblogs.com/pansidong/p/18417971