zoukankan      html  css  js  c++  java
  • js auto expand array All In One

    js auto expand array All In One

    rows 自动扩展

    
    const rows = [
      {
          "name": "总计",
          "ins_num_10k": 0,
          "natural_ins_num_ratio": null,
          "cost_amount_10k": 96058.5732011944,
          "allpay_amount_10k": 0,
          "cpi": null,
          "roi_7": 0,
          "mau": 0,
          "_meta": {
              "ins_num_10k_trend": -1,
              "natural_ins_num_ratio_trend": null,
              "cost_amount_10k_trend": 1.2952897963,
              "allpay_amount_10k_trend": -1,
              "cpi_trend": null,
              "roi_7_trend": -1,
              "mau_trend": -1,
          }
      },
      {
          "name": "其他",
          "ins_num_10k": 0,
          "natural_ins_num_ratio": null,
          "cost_amount_10k": 0.00294292,
          "allpay_amount_10k": 0,
          "cpi": null,
          "roi_7": 0,
          "mau": 0,
          "_meta": {
              "ins_num_10k_trend": -1,
              "natural_ins_num_ratio_trend": null,
              "cost_amount_10k_trend": null,
              "allpay_amount_10k_trend": -1,
              "cpi_trend": null,
              "roi_7_trend": null,
              "mau_trend": -1,
          }
      },
    ];
    
    const autoExpandRows = (arr = [], name = 'row_name') => {
      const result = [];
      for (const obj of arr) {
        const newObj = {
          [name]: `${obj[name]}趋势`,
          // _meta: obj._meta,
          // _meta: {},
        };
        for (const key in obj._meta) {
          const newKey = key.replace(/_trend/, '');
          newObj[newKey] = obj._meta[key];
        }
        result.push(obj);
        result.push(newObj);
      }
      return result;
    };
    
    const test = autoExpandRows(rows);
    
    console.log('test', test);
    
    

    refs



    ©xgqfrms 2012-2020

    www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

    原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!


    xgqfrms
  • 相关阅读:
    第12章,存储类别、链接和内存管理
    第11章 字符串和字符串函数
    第10章 数组和指针
    第9章 函数
    第8章 字符输入/输出和输入验证
    第7章,c语言控制语句:分支和跳转
    第六章,处语言控制语句:循环
    中国互联网发展史
    世界互联网发展史
    世界计算机发展史
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/15806003.html
Copyright © 2011-2022 走看看