The problem of integrating multiple element data in an array by JS

specifically, put the following

var targets = [
    {targetIds:[1],zone_id: 10000},
    {targetIds:[2],zone_id: 10000},
    {targetIds:[3],zone_id: 10001}
    {targetIds:[4],zone_id: 10000}
]

becomes like this:

var targets = [
    {targetIds:[1,2,4],zone_id: 10000},
    {targetIds:[3],zone_id: 10001}
]

requires that multiple zone_id corresponding targetIds can be integrated together

Mar.17,2021

var targetsMap = {}
var result = []
targets.forEach(function(item){
  if (targetsMap[item.zone_id]) {
    targetsMap[item.zone_id] = targetsMap[item.zone_id].concat(item.targetIds)
  } else {
    targetsMap[item.zone_id] = item.targetIds
  }
})
Object.keys(targetsMap).forEach(function(key) {
  result.push({
    targetIds: targetsMap[key],
    zone_id: key,
  })
})
console.log(result)
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-1b447f1-2c6fc.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-1b447f1-2c6fc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?