Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Shopify Community Downtime: The Shopify Community will be down December 5th for 15 minutes between 3pm and 4pm EST. Thank you for your understanding.

Append/Insert OBJECT to an array of objects

Append/Insert OBJECT to an array of objects

Darkbound
Tourist
7 0 0

How do I insert an object into an array of objects?

I have a for loop that is looping through one array and I have code that is filtering it by some properties to extract the objects that I need from it, the issue is that I want these objects to also be in an array:

  {% for uniqueVariant in uniqueVariants %}
    {% assign uniqueFirstAvailableVariants = product.variants | where"option1"variants[forloop.index] | where"available"true | first %}
  {% endfor %}

So how do I initialize uniqueFirstAvailableVariants as an empty array and then just insert the matching objects in it? Because right now uniqueFirstAvailableVariants is giving me just one object and it is the last object that is found that matches the conditions (and tha tis expected since its not an array)

Replies 0 (0)