The problem of converting an array format into an object array in the format of an array of objects, such as the format of an array, and the format of an array.

convert the type into an array of
, into an array of objects (a set of files with the same Q year), pray for a good method
, and convert it into an array of objects, such as an array of objects, , an array of types such as an array of objects, , an array of objects (files with the same Q year), a set of files in the same Q year, and a good method .
   [ 
        {"id":1,"name":"Q2018","children":[
            {"id":11,"name":"x_Q2018_st"},
            {"id":12,"name":",y_Q2018_rs"}
        ]},
        {"id":2,"name":"Q2017","children":[
            {"id":21,"name":"z_Q2017_r_n"},
            {"id":22,"name":"a_b_Q2017_r_n"}
        ]},
    ];


Jul.02,2021

there is no good way
can only regularly take numbers for array processing

clipboard.png

['x_Q2018_st','y_Q2018_rs','z_Q2017_r_n','a_b_Q2017_r_n'].reduce((s,v)=>{
    var _tag = v.match(/Q\d{4}/)[0];
    var index = s.findIndex(val=>val.name == _tag);
    if(!~index){
        index = s.length;
         s.push({
            id: index+1,
            name: _tag,
            children:[]
        })
    }
    s[index].children.push({
        id: ''+(index+1)+(s[index].children.length+1),
        name: v
    })
    return s
}, [])
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3794d-2c09b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3794d-2c09b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?