Hello, I am making a filter for my school assignment. It dynamically filters the data based on the radio box.
I created an object to store my data. And I store the selected fruit into an array
const fruits = {
"tomatos": {
"Id": 1,
"colors": ["red", "yellow", "orange", "black"],
},
"apple": {
"Id": 2,
"colors": ["red", "yellow", "black"]
}
}
const selected = []
I am able to filter the object, but I m having some issues getting the colors array.
showColors: function() {
const filtered = Object.keys(fruits)
.filter(key => selected.includes(key))
.reduce((obj, key) => {
obj[key] = fruits[key];
return obj;
}, {});
}
}
For example, if I check “Apple”, my selected will be [‘apple’], but for my filtered, I am getting
{
"apple": {
"Id": 2,
"colors": ["red", "yellow", "black"]
}
}
Instead of having an extra wrapping div, how can I get only the inside part
{
"Id": 2,
"colors": ["red", "yellow", "black"]
}