我有对象
data = {
others: [
{
code: "A", label: "0-A"
},
{
code: "B", label: "0-B"
},
...,
{
code: "N", label: "0-N"
}
]
}
在将其发送到axios查询之前,我需要将other_
前缀添加到code
值(例如,other_N
(:
await axios.post(`${URL}`, { data })
类似的东西
let data = {
others: [{
code: "A",
label: "0-A"
},
{
code: "B",
label: "0-B"
},
{
code: "N",
label: "0-N"
}
]
};
let modifiedData = data.others.map(x => {
x.code = `other_${x.code}`;
return x;
})
console.log(modifiedData);
您可以使用Array.map函数来操作数据对象
data.others.map(x => { return { other_code: x.code, label: x.label }})