iot-manage-dashboard/apps/web-tdesign/src/enum/index.ts
2025-11-10 16:30:19 +08:00

14 lines
291 B
TypeScript

export const toObject = <T extends Record<string, any>>(
arr: T[],
keyField: keyof T,
valueField: keyof T,
): Record<string, any> => {
const result: Record<string, any> = {};
for (const item of arr) {
result[item[keyField] as any] = item[valueField];
}
return result;
};