2 回答
TA贡献1798条经验 获得超3个赞
let data = [
{
"season": "autumn",
"firstContactPersonName": "John",
"firstContactPersonPhone": "46442644",
"secondContactPersonName": "Jhonny",
"secondContactPersonPhone": "46442644"
},
{
"season": "christmas",
"firstContactPersonName": "Tommy",
"firstContactPersonPhone": "46442644",
"secondContactPersonPhone": "Thomas"
},
{
"season": "winter",
"firstContactPersonPhone": "46442644",
"firstContactPersonName": "Peter",
"secondContactPersonName": "Tom",
"secondContactPersonPhone": "44664455"
}
]
const dateArray = ["christmas=2020-12-28", "autumn=2020-08-28", "winter=2020-02-28"]
let updatedData = data.map((x)=> {
let season = x.season;
x.date = dateArray.find(e=> e.indexOf(season) > -1).split("=")[1];
return x;
})
console.log(updatedData)
TA贡献1821条经验 获得超6个赞
不是用开关,但这是一种方法:
dateArray.forEach(date => {
if (date.includes("autumn")) {
data.data[0] = { ...data.data[0], date };
} else if (date.includes("christmas")) {
data.data[1] = { ...data.data[1], date };
} else if (date.includes("winter")) {
data.data[2] = { ...data.data[2], date };
}
});
添加回答
举报