原有数据形式:
res = [
{
id:1,
name:‘西安’,
address:‘西部’
},
{
id:2,
name:‘扬州’,
address:‘南部’
}
]
需求
res = [
{
id:1,
name:‘西安’
},
{
id:2,
name:‘扬州’
},
1、map()
const ary = res.map((item) => {
return {
id:item.id,
name:item.name
}
})
2、forEach()
res.forEach(item => {
ary.push({
id: item.id,
name: item.name
})
})
两者区别:https://blog.youkuaiyun.com/qq_39207948/article/details/80357569