I am trying to organize my data by creating an array and listing each material based on its status. Here is the structure of my current array:
let data = [
{
Name: 'House 1',
Details:[
{Materials: 'Door', Status: 'Delivered'},
{Materials: 'Closet', Status: 'Pending'},
{Materials: 'Chair', Status: 'Pending'},
{Materials: 'Kitchen', Status: 'Delivered'},
{Materials: 'Door Knob', Status: 'Delivered'}
]
},
{
Name: 'House 2',
Details:[
{Materials: 'Cabinet', Status: 'Delivered'},
{Materials: 'Kitchen', Status: 'Delivered'},
{Materials: 'Door', Status: 'Ongoing'},
{Materials: 'Chair', Status: 'Ongoing'},
{Materials: 'Window', Status: 'Cancelled'}
]
},
//Other codes here...
];
My goal is to display a breakdown of the status for each material in the expected output format shown below.
Expected Output:
[
0: 'House 1'
[
0: 'Delivered': [ 0: 'Door', 1: 'Kitchen', 2: 'Door Knob' ]
1: 'Pending': [ 0: 'Closet, 1: 'Chair' ]
]
1: 'House 2'
[
0: 'Cancelled': [ 0: 'Window' ]
1: 'Delivered': [ 0: 'Cabinet', 1: 'Kitchen' ]
2: 'Ongoing': [ 0: 'Chair', 1: 'Door' ]
]
]
//where 0:, 1:, 2: represent the index of each nested array
//the indexes have been added similar to console.log output for reference but they are not mandatory in the final result
I have attempted to use forEach and .reduce methods, but I am encountering issues with my code execution. Your assistance in resolving this problem would be greatly appreciated :)