jsは1次元配列を2次元配列とグループに変換します

let arr = [{
    
    a:'W',b:'W01'},{
    
    a:'W',b:'W02'},{
    
    a:'WC',b:'WC01'},{
    
    a:'WC',b:'WC02'},{
    
    a:'WC',b:'WC02'},{
    
    a:'WC',b:'WC02'}]
let map= {
    
    };
arr.forEach(item=>{
    
    
       if(map[item.a]){
    
    
           map[item.a].push(item.b);
       }else{
    
    
           map[item.a] = [item.b];
       } 
   })
   console.log(map);

出力効果は図のようになります
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/weixin_44812604/article/details/128824991