首页 > 编程语言 > 详细

改变数组对象的属性名称,不改变属性值

时间:2019-10-25 21:27:16      阅读:412      评论:0      收藏:0      [点我收藏+]
  console.log(this.oneAgData[‘Detail‘]);
    this.DetailFirstColumn = [];
    this.DetailSecondColumn = [];
    // this.DetailThirdlyColumn = [];

    for (var j = 0; j < this.oneAgData[‘Detail‘].length; j++) {   //--循环所有的列
      if (j % 3 == 0) {
        this.DetailFirstColumn.push(this.oneAgData[‘Detail‘][j]);
      } else if (j % 3 == 1) {
        let obj = {};
        for (let k in this.oneAgData[‘Detail‘][j]) {
          obj[k + ‘1‘] = this.oneAgData[‘Detail‘][j][k];
        }
        this.DetailFirstColumn.push(obj);
      } else if (j % 3 == 2) {
        let obj = {};
        for (let k in this.oneAgData[‘Detail‘][j]) {
          obj[k + ‘2‘] = this.oneAgData[‘Detail‘][j][k];
        }
        this.DetailFirstColumn.push(obj);
      }
    }

    console.log(this.DetailFirstColumn);

    for (let i = 0; i < this.DetailFirstColumn.length; i++) {
      if (i % 3 == 0) {
        this.DetailSecondColumn.push(this.DetailFirstColumn[i]);
      } else if (i % 3 == 1) {
        Object.assign(this.DetailSecondColumn[this.DetailSecondColumn.length - 1], this.DetailFirstColumn[i]);
      } else if (i % 3 == 2) {
        Object.assign(this.DetailSecondColumn[this.DetailSecondColumn.length - 1], this.DetailFirstColumn[i]);
      }
    }
    console.log(this.DetailSecondColumn);

  

改变数组对象的属性名称,不改变属性值

原文:https://www.cnblogs.com/LFxanla/p/11740895.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!