Object reorganization of js array

arr = [

]
{"param":"CASH_LIMIT"},
{"param":"green"},
{"regular":"="},
{"regular":"!="},
{"value":"15000"},
{"value":"2323"}

]

changeArr = [

]
{"param":"CASH_LIMIT","regular":"=","value":"15000"},
{"param":"green","regular":"!=","value":"2323"},  

]

how to traverse to turn arr into changeArr

Jun.23,2021

function trans (arr) {
  return arr.reduce((sum, cur, index) => {
    let keys = Object.keys(cur)
    let tmp = sum[index % 2]
    keys.forEach(key => {
      tmp[key] = cur[key]
    })
    return sum
  }, [{}, {}])
}
trans(arr)

I don't know what function you want to achieve? If you simply want to integrate objects, and if you do as shown above in the arr array, then you can just copy the number of objects according to the number of objects. As shown in the following code:

function funchan(arr,count)
{ 
    if (!Array.isArray(arr)) return null; 
    let len = arr.length; 
    let newLen = len / count; 
    let result = new Array();  
    for (let i =0; i < newLen; iPP) 
    { 
        let temp = {}; 
        for (let j = 0; j < count; jPP)
        { 
            temp = Object.assign(temp,arr[j*newLen + i]);
        } 
        result.push(temp);   
    }
    return result;
}

clipboard.png


the rule seems to be odd in the first object and even in the second object

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