The problem of converting a specific format string to json format in JS

A string is as follows:
Table name 1 @ Field 1 ~ Table name 1 @ Field 2 ~ Table name 2 @ Field 1 ~ Table name 2 @ Field 2

how to reasonably handle it in json format

 {
     1:[12],
     2:[1, 2]
 }
Mar.04,2021

var str = '1@1~1@2~2@1~2@2'

var obj = str.split('~').reduce((state, item) => {
  var [tname, fname] = item.split('@')
  if (state[tname]) {
    state[tname].push(fname)
  } else {
    state[tname] = [fname]
  }
  return state
}, {})

that's about it

var str='1@1~1@2~2@1~2@2'
var arr=str.split("~")
var obj={}
for(var i=0;i<arr.length;iPP){ 
  var temp=arr[i].split("@")
  var key=temp[0]
  var value=temp[1]
  obj[key]=(obj[key]||[]).concat([value])
}
console.log(JSON.stringify(obj))
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-1e413d2-44909.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-1e413d2-44909.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?