duan602728596
2022-07-20 16:01:04 +08:00
type Item = Record<string, string>;
const headers: Item = {
a: 'sss',
b: '京津冀'
};
const data: Array<Item> = [
{ a: '迭代', b: '迭代' },
{ a: '测试', b: '测试' },
{ a: '哦哦', b: '偶偶' }
];
const concatHeaderAndData = (header: Item, data: Array<Item>): Array<Item> => {
return data.map((item: Item): Item => {
return Object.keys(item).reduce((newData: Item, key: string): Item => {
const newKey = header[key] || key;
newData[newKey] = item[key];
return newData;
}, {});
});
};