get an object in an array based on it's property

Options
Hello,
I'm parsing a "product" object (json) that contains a property "images" which is an array of objects.
{
   ...,
   images:[
      {
         type:"primary",
         width:600,
         uri:"xxx"
      },
      {
         ...
      }
   ],
   ...
}

I'd like to get the uri property of the image that has the type property set to "primary", but i can't figure out how to do that.

There are several filters available on product.images, but none of them seems to let me filter the array according to a property of the objects it contains...

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    I would use the function Array: Find First Element

    Use the images [] array as the array

    Then set $this.type = primary

    This will return the object that is type primary, from there you can use dot notation to isolate and return the URI