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