后端返回的原始數(shù)組
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); //返回數(shù)組["t1","t2","t3","t4","t5",]
需要多個屬性
let newTecherList1 = techerList.map(item=>({
techerId:item.techerId,
techerName:item.techerName,
}))
console.log(newTecherList1); //返回數(shù)組[{techerId: "t1", techerName: "張三"},...]
map返回的是一個新的數(shù)組