Files
sunProduct/src/utils/map.ts
2026-04-23 17:59:36 +08:00

11 lines
345 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 合并两个对象数组并去重(基于 id,后面的覆盖前面的)
*/
export function mergeObjectsAndDedupe<T extends { id?: string }>(arr1: T[], arr2: T[]): T[] {
const map = new Map(arr1.map((item) => [item.id, item]));
arr2.forEach((item) => {
if (item.id) map.set(item.id, item);
});
return [...map.values()];
}