I'm trying to group data from an object to a multidimensional array
In the last three days I've tried multiple ways to get the result I want. Since I've no luck, probably because of my poor knowledge of ReactJS/ES6. I hope someone can explain how I can get this to work.
I think I'll have to use the map function. Within the map function, a filter function to get the unique companies and then a loop to add the table information.
The end result should be like this: https://wireframe.cc/No5uB7
The data I'd like to filter:
{
"viewings": [
{
"companyXXX": "company-XXX",
"time_start": "02/04/2019",
"time_end": "03/04/2019 11:59"
},
{
"companyXXX": "company-XXX",
"time_start": "14/04/2019",
"time_end": "15/04/2019 11:59"
},
{
"companyYYY": "company-YYY",
"rejection": 40,
"time_start": "14/04/2019",
"time_end": "15/04/2019 11:59"
}
]
}
The code I still have that isn't working
genData(data) {
const di = data.viewings;
let mps = [];
di.map(m => mps.push(m.company));
mps = Array.from(new Set(mps));
console.log( mps );
let mps = [];
di.map((m) =>
console.log( di.filter(mps => m.company) )
);
}