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