Our array consists of various items:
const array = [object1, object2, ...]
The structure of each item is defined as follows:
type Item = {
id: number;
title: string
contact: {
id: number;
name: string;
};
project: {
id: number;
name: string;
} | null;
};
Our goal is to organize the data into an array with the following structure:
type Contact = {
id: number;
name: number;
project: Array<{
id: number;
name: number;
items: Array<{
id: number;
title: number;
}>;
}>;
};
const array2 = [contact1, contact2, ...]
In each Item, if a project exists, it is associated with the contact of that specific item.
How can we efficiently map this data?