In my current array, the structure looks like this:
const books[{
name: 'book1',
id: '1',
fromStatus: [{
name: 'Available',
id: 1
}, {
name: 'Free',
id: 2
}],
toStatus: [{
name: 'Not available',
id: 1
}, {
name: 'Not free',
id: 2
}]
}, {
name: 'book2',
id: '2',
fromStatus: [{
name: 'Burnt',
id: 1
}],
toStatus: [{
name: 'Not burnt',
id: 1
}]
}]
I am looking to create a new array with the following structure:
const statusFromTo[{
{
id: 1,
fromStatusName: 'Available',
toStatusName: 'Not available'
},
{
id: 2,
fromStatusName: 'Burnt',
toStatusName: 'Not burnt'
},
{
id: 3,
fromStatusName: 'Free',
toStatusName: 'Not free'
},
}]
The matching of from and to statuses is based on their respective ids. For instance, Free and Not Free both have an id of 3, Available and Not Available both have an id of 1, Burnt and Not Burnt both have an id of 2.
I've attempted different forEach and .map methods but haven't been successful so far. Any suggestions or help would be appreciated! I am using TypeScript for this task.