If you reorganize some unfixed fields in the array into a new field

/ / primitive array

  goodsSkusList: [
    {
      attrSymbolPath: "0,10",
      attrValue0: "",
      attrValue1: "S",
      batchPrice: 11,
      batchQuantity: 111,
      marketPrice: 11,
      store: 22,
      univalence: "11",
      warnStore: 111
    },
    {
      attrSymbolPath: "1,10",
      attrValue0: "",
      attrValue1: "S",
      batchPrice: 11,
      batchQuantity: 111,
      marketPrice: 11,
      store: 22,
      univalence: "11",
      warnStore: 111
    }
  ]
  
  

only batchPrice, batchQuantity,marketPrice,store,univalence,warnStore is a fixed field, and other fields are not fixed. It may be possible from attrValue0 to attrValue100. How to reorganize an unfixed field into a new field, attrSku?? The following figure

clipboard.png

Nov.29,2021

test = ()=>{
     // (obj2obj1)
    let getDifferentFields1 = (obj1, obj2)=>{
        let sameFields = {...obj1}, 
            differentsFields = {...obj2};
            
        // differentsFields 
        for(let key in sameFields){
            sameFields[key] = differentsFields[key];
            delete differentsFields[key];
        }
        return [sameFields, differentsFields];
    }

    // 
    let definitiveFields = {
      batchPrice: "",
      batchQuantity: "",
      marketPrice: "",
      store: "",
      univalence: "",
      warnStore: ""
    };
    
    // 
    let data = [{
      attrSymbolPath: "0,10",
      attrValue0: "",
      attrValue1: "S",
      batchPrice: 11,
      batchQuantity: 111,
      marketPrice: 11,
      store: 22,
      univalence: "11",
      warnStore: 111
    },
    {
      attrSymbolPath: "1,10",
      attrValue0: "",
      attrValue1: "S",
      batchPrice: 11,
      batchQuantity: 111,
      marketPrice: 11,
      store: 22,
      univalence: "11",
      warnStore: 111
    }];
    
    // ()
    let newData = data.slice().map( item => {
        let [sameFields, differentsFields] = getDifferentFields1({...definitiveFields}, item);
        return {
            ...sameFields,
            attrSku: [differentsFields]
        };
    });

    console.log(newData);
}
    
test();


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