后端返回的原始数组
let techerList = [
{techerId:'t1',techerName:'张三',sex:'男',email:'123456789@qq.com'},
{techerId:'t2',techerName:'李四',sex:'女',email:'123456789@qq.com'},
{techerId:'t3',techerName:'王五',sex:'男',email:'123456789@qq.com'},
{techerId:'t4',techerName:'赵六',sex:'女',email:'123456789@qq.com'},
{techerId:'t5',techerName:'孙七',sex:'男',email:'123456789@qq.com'}
]
只需要一个单独的属性
let newTecherList = techerList.map(item=>{
return item.techerId
})
console.log(newTecherList); //返回数组["t1","t2","t3","t4","t5",]
需要多个属性
let newTecherList1 = techerList.map(item=>({
techerId:item.techerId,
techerName:item.techerName,
}))
console.log(newTecherList1); //返回数组[{techerId: "t1", techerName: "张三"},...]
map返回的是一个新的数组
网友评论