我想把数组里面对应的属性和属性值转换为字符串怎么实现呢?let data=[ {name:"小明",status:false}, {name:"小红",status:false}, {name:"小张",status:true}, {name:"小墙",status:false}, {name:"小粉",status:false}, {name:"小军",status:false}, {name:"小钰",status:false}, {name:"小访",status:true}, {name:"小源",status:false}, {name:"小方式",status:false}, {name:"小佛",status:false}, {name:"小付款",status:false}, {name:"小哦咯",status:false}, {name:"小来了",status:false}, ]; console.log(data); 我想转换为 let obj={ "小明":false, "小红":false, "小张":true, "小墙":false, "小粉":false, "小军":false, "小钰":false, "小访":true, "小源":false, "小方式":false, "小佛":false, "小付款":false, "小哦咯":false, "小来了":false, }; console.log(obj); 这种怎么转换呢?
1 回答
POPMUISE
TA贡献1765条经验 获得超5个赞
let data=[
{name:"小明",status:false},
{name:"小红",status:false},
{name:"小张",status:true},
{name:"小墙",status:false},
{name:"小粉",status:false},
{name:"小军",status:false},
{name:"小钰",status:false},
{name:"小访",status:true},
{name:"小源",status:false},
{name:"小方式",status:false},
{name:"小佛",status:false},
{name:"小付款",status:false},
{name:"小哦咯",status:false},
{name:"小来了",status:false},
];
let obj= {};
data.map(d=>obj[d.name]=d.status);
console.log(obj);
添加回答
举报
0/150
提交
取消