Im looping through some collections (called categories in Shopify Liquid), and I need to cast all those collections into an array, so I can access their indexes.
What Im doing now is this:
{% for link in linklists[page.handle].links limit:1 %}
{% assign collection = link.object %}
// Im doing the above code somewhere above in the liquid file, thats where I get the link.object
<script>
var collections = {{ link.object | json }};
console.log(collections);
</script>
And this is the result I get:
I need the result to be like this, in an array:
How can I cast those set of objects to array like I have shown for the images below?
/********** EDIT *******/
When I use Array.of(), like this:
console.log(Array.of(collections));
But all those Objects are still not in an array. Maybe push it up one level?
3
Answers
not sure what you’re trying to achieve but have a look at the Array.of method.
nevertheless – it looks like your collections are actually a collection and you therefore you maybe looking for an array in a higher scope defined and just push / concat them together once you reach your code with your collection.
Why are you initiating the collections variable inside the for loop? Try this
The object is probably more useful in most cases but you can so something like this: