I'm working on a headless Shopify store using Gatsby, and am having some trouble building a robust product option picker.
I have an options object that looks like this:
{
extras: "Pouch only",
}
The key and value will be different for every product, so I won't know the values.
I have a variants array that will have a key/value pair that matches this object. Here is the shape of the variants array:
[
{
extras: "Pouch only",
...otherValues,
},
{
extras: "Add tassel",
...otherValues,
},
{
extras: "Add charm",
...otherValues,
},
{
extras: "Add tassel & charm",
...otherValues,
},
{
sizes: "S",
...otherValues,
},
{
sizes: "M",
...otherValues,
},
{
sizes: "L",
...otherValues,
},
{
sizes: "XL",
...otherValues,
},
];
If I knew the name of the variant ahead of time, I could do something like this:
const newVariant = variants.find((v) => {
return v.extras === options.extras;
});
How can I do the same thing without knowing the name of the key?