数组转对象的方法
const Arr = [
{ label: '男', value: 0 },
{ label: '女', value: 1 },
]
const needObj = {}
Arr.forEach((item) => {
const key = item.value
const value = item.label
needObj[key] = value
})
console.log(needObj) // {0: '男', 1: '女'}
收集项目中遇到问题从中得到解决方法的链接。

浙公网安备 33010602011771号