I have a question about sorting a dictionary object is JS es6. I am trying to filter the array but still keep the structure of an array in each month's object. Here is a mock of the data:
"soldListings": {
"Jan - 2020": [
{
"id": 159,
"user_id": 1,
"type_id": 1,
},
{
"id": 173,
"user_id": 1,
"type_id": 1,
},
{
"id": 563,
"user_id": 1,
"type_id": 2,
}
],
"Dec - 2019": [
{
"id": 183,
"user_id": 1,
"type_id": 1,
}
],
"Oct - 2019": [
{
"id": 176,
"user_id": 1,
"type_id": 1,
}
]
}
If it were a flat array of objects i would do something like:
typeFilter = data.filter((listing) => {
if(listing.type_id){
return listing.type_id == this.state.soldListTypeFilter ;
}
});
UPDATE
I need the output to be in the same format as the input. For example if i were to filter the object by type_id = 2 it would return this:
"soldListings": {
"Jan - 2020": [
{
"id": 563,
"user_id": 1,
"type_id": 2,
}
],
"Dec - 2019": [
],
"Oct - 2019": [
]
}