I have an array of all objects stored in a state variable. I also have another state variable that grabs a user input value from a drop down menu.
The all objects state is filtered and creates a new array with just the filtered values.
My issue is that I don't know how to make the object property dynamic so I can return the value.
const SnowboardArray = [
{
id: 1,
name: "Thunder Bolt",
availability: "in stock",
shape: "directional",
Level: "Expert",
size: "156",
price: "500",
sprite: thunderBolt,
},
{
id: 2,
name: "Surfer",
availability: "in stock",
shape: "directional",
Level: "Expert",
size: "154",
price: "800",
sprite: surfer,
}
]
// Function to filter the main array with the selected filter value stored in the state
function getFilteredList() {
if (!filteredObjects) {
return allObjects;
}
// object grabs the object in the array / size refers to the property (this needs to be dynamic) / filteredObjects is the user input which refers to the proeprty value.
return allObjects.filter((object) => object.size === filteredObjects
)
}