请问怎么拆分这种数组?

var data = [

{'10':[{ "男":10},{ "女":8}]},
{'10-20':[{ "男":20},{ "女":80}]},
{'20-30':[{ "男":30},{ "女":70}]},
{'30-40':[{ "男":50},{ "女":40}]},

];
以上这个数组我想拆分成以下这种格式,怎么弄,求教?

Arr1 = ['10','10-20','20-30','30-40']; //年龄

Arr2 = ['10','20','30','50']; //男

Arr3 = ['8','80','70','40']; //女

阅读 202
评论 2019-08-14 提问
    2 个回答
    lulu_up
    • 2.1k
    function task(data){
                     let Arr1 = [],
                         Arr2 = [],
                         Arr3 = [];
                    data.map(item=>{
                        let key = Object.keys(item)[0];
                      Arr1.push(key) 
                      Arr2.push(item[key][0]['男']);
                      Arr3.push(item[key][1]['女'])
                    })
                    
                    return {
                        Arr1,Arr2,Arr3
                    }
                }

    图片描述

    评论 赞赏 2019-08-14