-1

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']; //女

查看全部 2 个回答

1

已采纳
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
                }
            }

图片描述

推广链接