Array object reordering

   arr = [
        {id:1,name:""},
        {id:2,name:"", children:[
            {id:4,name:""}
            ]},
        {id:3,name:""}
    ];
    

how do you reorder the array above into the following format?

   newArr = [
        {id:1,name:""},
        {id:2,name:""},
        {id:4,name:""}
        {id:3,name:""}
    ];
    

guys, help me take a look. Thank you

Mar.25,2021

function trans (arr) {
  return [].concat.apply([], arr.map(cur => {
    return [{id: cur.id, name: cur.name}].concat(cur.children ? trans(cur.children) : [])
  }))
}
let newArr = trans(arr)

let arr = [
    {id:1,name:''},
    {id:2,name:'', children:[
            {id:4,name:''}
        ]},
    {id:3,name:''}
];

function format(arr) {
    return arr.reduce((result, item) => {
        return [...result, {id:item.id,name:item.name}, ...item.children || []]
    },[]);
}

console.log(format(arr));
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-1ea5468-1d44.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-1ea5468-1d44.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?