Q:

Javascript, return first (sub) object that matches

I have an array of objects which I am trying to look through to grab the first child object that matches a certain object I am giving it. So my object looks like so : 
const filteredVariants = [
{
   name: "Test0",
   images: [
   {
    name: "test0img1",
    shot_type: "swatch"
   }]
   }, {
   name: "Test1",
   images: [
   {
    name: "test1img1",
    shot_type: "product"
   },
   {
    name: "test1img2",
    shot_type: "product"
   }]
}]

So what I am looking to do is look through this object, specifically inside images and find the first object that has shot_type: "product" and return that. So, in this case I am trying to get it to return to me :
{
name: "test1img1",
shot_type: "product"
}

Here is what I have so far : 
 const firstProductImage = _.find(filteredVariants, _.flow(
    _.property('images'),
    _.partialRight(_.some, { shot_type: 'product' })
 ));

This is partially the way there, except it's returning the entire parent object, when I just need the child image object. I have tried running over a map and filter as well, but those approaches were not as clean as this one. I am wondering if there is a way to tell lodash in this case to just return that first child node that matches { shot_type: 'product' } .
I am using lodash, but if this is possible in plain javascript, that would be great too. Thanks!

A:

You could iterate filteredVariants and images and if found, then assign the object to result. The returned truthy value ends both loops.
Version with Array#some:

var filteredVariants = [{ name: "Test0", images: [{ name: "test0img1",  shot_type: "swatch" }]}, { name: "Test1", images: [{ name: "test1img1",  shot_type: "product" }, { name: "test1img2", shot_type: "product" }] }],
    result;

filteredVariants.some(variant =>
    variant.images.some(image => image.shot_type === "product" && (result = image))
);

console.log(result);

Version with Array#reduce and Array#find:

var variants = [{ name: "Test0", images: [{ name: "test0img1",  shot_type: "swatch" }]}, { name: "Test1", images: [{ name: "test1img1",  shot_type: "product" }, { name: "test1img2", shot_type: "product" }] }],
    result = variants.reduce((r, variant) =>
        r || variant.images.find(image => image.shot_type === "product"),
        undefined
    );

console.log(result);

