const arr = [
{ id: 1, value: "白色" },
{ id: 2, value: "黑色" },
{ id: 3, value: "粉色" }
]
const a = arr.reduce((p, c) => Object.assign(p, { [c.id]: c.value }), {})
console.log(a)
// {
// 1: "白色,
// 2:"黑色",
// 3: "粉色"
// }
// 递归
const getOption = (data)=> {
return data.reduce((p, c) => {
const item = c.childList && c.childList.length > 0 ? getOption(c.childList) : []
return p.concat(c).concat(item)
}, [])
}