利用reduce()方法
const form = ref([
{
type: '工作日',
value: 1,
},
{
type: '休息日',
value: 2,
},
{
type: '法定假日',
value: 3,
},
{
type: '法定调休日',
value: 4,
},
]);
const formattedData = form.value.reduce<{ [key: string]: number }>((acc, cur) => {
acc[cur.type] = cur.value;
return acc;
}, {});
console.log(formattedData);
会得到类似以下键值对的json数据


8539

被折叠的 条评论
为什么被折叠?



