xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(42)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-01-15 npm config set registry
2021-01-15 VuePress plugins All In One
2021-01-15 surge & free online docs website service
2021-01-15 Front End Frameworks Trending 2021
2021-01-15 vuepress & package.json lock version
2020-01-15 Vue & SSR & asyncData All In One
2019-01-15 SVN & GIT
点击右上角即可分享
微信分享提示