js實現對象的key替換


function


    renameKeys(obj, newKeys) {
      const keyValues = Object.keys(obj).map(key => {
        const newKey = newKeys[key] || key;
        return { [newKey]: obj[key] };
      });
      return Object.assign({}, ...keyValues);
    },
    
    let newKeys = {}
//  獲取對象的key集合進行處理(此處是處理 大寫轉小寫)
    Object.keys(object).forEach(item => {
      let lowItem = item.toLowerCase()
       this.$set(newKeys, item, lowItem )
     })
     let uploadObj = this.renameKeys(r.data.data[0], newKeys)

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM