var arr = [{ "aaa": { "name": "小敏", "price": "18", "count": 2, "num": 5 }, "bbb": { "name": "小李", "price": "18", "count": 1, "num": 11 }, "ccc": { "name": "小华", "price": "18", "count": 1, "num": 18 }}]var arr1 = [ {"id":"aaa","count":2}, {"id":"bbb","count":1}, {"id":"ccc","count":1}]请问上面的arr怎么转成下面arr1格式 用原生js
1 回答
慕桂英546537
TA贡献1848条经验 获得超10个赞
var arr = [{
"aaa": {
"name": "小敏",
"price": "18",
"count": 2,
"num": 5
},
"bbb": {
"name": "小李",
"price": "18",
"count": 1,
"num": 11
},
"ccc": {
"name": "小华",
"price": "18",
"count": 1,
"num": 18
}
}];
var tArr = [];
arr.forEach((item,index)=>{
tArr.push(
Object.keys(item).map((v,i)=>{
return {
id : v,
count : item[v].count
}
})
);
});
console.log(tArr);
添加回答
举报
0/150
提交
取消