用es6
第一種: ...item根據你的需求,可要可不要
let arr = [
{id: 1, title: "綁定手機"},
{id: 2, title: "實名認證"},
{id: 3, title: "游戲分享任務"},
{id: 12, title: "游戲體驗任務"},
{id: 13, title: "游戲時長任務"}
]
const res = arr.map(item=>({...item, label: item.title, value: item.id}))
console.log(res);
第二種: 比較傻瓜的
let arr = [
{id: 1, title: "綁定手機"},
{id: 2, title: "實名認證"},
{id: 3, title: "游戲分享任務"},
{id: 12, title: "游戲體驗任務"},
{id: 13, title: "游戲時長任務"}
]
let arrNew = arr.map((item) => {
item.label = item.title
item.value = item.id
return item
})
console.log(arrNew);
好好生活-_-