0

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

    )
 }
Gavin-walsh
  • 109
  • 6
  • 1
    Does this answer your question? [Accessing an object property with a dynamically-computed name](https://stackoverflow.com/questions/4244896/accessing-an-object-property-with-a-dynamically-computed-name) – Heretic Monkey Dec 29 '22 at 12:40

0 Answers0