js多对象遍历成数组集合

后端返回的数组格式

let = shop_info: {
2: {insert_time: "2015-06-08 11:03:08", shop_name: "优衣库官方旗舰店", shop_id: "2",},}
2: {insert_time: "2015-06-08 11:03:08", shop_name: "优衣库官方旗舰店", shop_id: "2",}
4: {insert_time: "2015-06-08 11:06:06", shop_name: "名鞋库运动直销店1", shop_id: "4",}
14: {insert_time: "2015-06-08 15:54:39", shop_name: "千手1", shop_id: "14", taskid: {6: "9", 7: "10"},}
16: {insert_time: "2015-06-08 16:31:59", shop_name: "YSL圣罗兰美妆官方旗舰店", shop_id: "16", taskid: ["3"],}
17: {insert_time: "2015-11 10:30:03", shop_name: "嘉得9197", shop_id: "17", taskid: {12: "14"},}
18: {insert_time: "2015-06-11 10:36:28", shop_name: "黛如歌原创汉服", shop_id: "18",}
}
// 使用for in 处理
function disposeData(Obj){
         let x ={};
         let list = [];
         for( x in Obj ){
           list.push(Obj[x])
         }
         return list
}
 let list = disposeData(shop_info)
 console.log(list)
 // 处理结果如下:
 [
	{insert_time: "2015-06-08 11:03:08", shop_name: "优衣库官方旗舰店", shop_id: "2",},}
    {insert_time: "2015-06-08 11:03:08", shop_name: "优衣库官方旗舰店", shop_id: "2",}
    {insert_time: "2015-06-08 11:06:06", shop_name: "名鞋库运动直销店1", shop_id: "4",}
    {insert_time: "2015-06-08 15:54:39", shop_name: "千手1", shop_id: "14", taskid: {6: "9", 7: "10"},}
    {insert_time: "2015-06-08 16:31:59", shop_name: "YSL圣罗兰美妆官方旗舰店", shop_id: "16", taskid: ["3"],}
    {insert_time: "2015-11 10:30:03", shop_name: "嘉得9197", shop_id: "17", taskid: {12: "14"},}
    {insert_time: "2015-06-11 10:36:28", shop_name: "黛如歌原创汉服", shop_id: "18",}
]

你可能感兴趣的:(javascript,js)