map转list | 对象转数组 | 美菜数据格式转换
阅读原文时间:2023年07月14日阅读:3

function formatData(tempObj){
let bigArr = [];
for(let p in tempObj){
let tempArrForeach1 = []
for(let key in tempObj[p]){
//数组层
tempArrForeach1.push(arrToObj(tempObj[p][key]));
}
bigArr.push((tempArrForeach1))
}
return bigArr;

function arrToObj(arr=\[\]){  
    var outObj = {};  
    //认为arr数组内Element所有字段一致  
    Object.keys(arr\[\]).forEach(key=>{  
        var arrChilds = Array.from(new Set((arr.map(v=>v\[key\])+'').split(',')));  
        if(arrChilds.length>){  
            outObj\[key\] = arrChilds;  
        }else if(arrChilds.length==){  
            outObj\[key\] = arrChilds\[\]  
        }  
    });  
    return outObj  
}  

}