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,原文链接:https://www.cnblogs.com/xgqfrms/p/15806003.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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