How to convert the array of the following examples into examples

example

[
    {
        id: 1,
        subId: null
    },
        {
        id: 2,
        subId: null
    },
    {
        id: 3,
        subId: 44
    },
    {
        id: 3,
        subId: 45
    }
]

want such a result

[
    {
        id: 1,
        subIds: null
    },
        {
        id: 2,
        subIds: null
    },
        {
        id: 3,
        subIds: [44, 45]
    }
]
Oct.11,2021

    //
    var _arr = [];
    //
    arr.sort((a, b) => { a = 213; return a.id - b.id; });
    //
    arr.push({id:Symbol(1),subId:Symbol(2)});
    arr = arr.reduce(function (p, r) {
      
      if (p.id === r.id) {
        p.subId = p.subId && (typeof p.subId) === "object" ? p.subId : [p.subId];
        r.subId = [...p.subId, r.subId];
        
        return r;
      }else {
        _arr.push(p);
        return r;
      }
    });
    console.log(_arr);

let obj = [
  {
    id: 1,
    subId: null
  },
  {
    id: 2,
    subId: null
  },
  {
    id: 3,
    subId: 44
  },
  {
    id: 3,
    subId: 45
  }
]
let new_arr = []; old_arr = [];
obj.forEach(item => {
  if (item.subId !== null) {
    new_arr.push(item)
  } else {
    old_arr.push(item)
  }
})
let id = new_arr.length + 1;
let result = new_arr.reduce((total, value, index, arr) => {
  total.id = id;
  total.subId = [total.subId];
  total.subId.push(value.subId)
  return total
})
old_arr.push(result) 
console.log(old_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-1e9c081-18a7.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-1e9c081-18a7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?