js 将一个数组中的部分字段,添加到另外一个数组中

原数组:
{"data":[{"id":"340129","parentId":"340100","name":"高新区","shortName":"高新技术产业开发区","sort":1,"type":3,"lng":"117.135790","lat":"31.831280","pinyin":"gaoxinjishuchanyekaifaqu"},

{"id":"340128","parentId":"340100","name":"经开区","shortName":"经济技术开发区","sort":1,"type":3,"lng":"117.248120","lat":"31.784890","pinyin":"jingjijishukaifaqu"}]}

截取部分字段
var area = []
data.forEach((item) => {
area.push({ areaCode: item.id, areaName: item.name })
})

新数组
"area":[
{"areaCode":"340129","areaName":"高新区"},
{"areaCode":"340128","areaName":"经开区"}
]

你可能感兴趣的:(js 将一个数组中的部分字段,添加到另外一个数组中)