Skipping iteration of map loop

This is the javascript equivalent of what I want to do

const data = [
 {
   name:'test'  
  },
  {
     name:'test2'
   }
]

let arr = [];

let length = data.length;

const searchTerm = 'te';

data.forEach((val)=>{
   if(!val.name.includes(searchTerm)){
     continue;
   }

   arr.push(val);
})

return arr;

This is what I have so far

await client.query(
            Map(
                Paginate(Documents(Collection(pool)), { size: 10000 }),
                Lambda('poolRef',
                    Let(
                        {
                            poolDoc: Get(Var('poolRef'))
                        },
                        Do(
                            If(
                                ContainsStr(LowerCase(Select(['data', 'name'], Var('poolDoc'))), name),
                                Do(
                                    {
                                        _id: Select(["ref", "id"], Var("poolDoc")),
                                        name: Select(["data", "name"], Var("poolDoc"))
                                    }
                                ),
                                null
                            )
                        )

                    )
                )
            )
        );

The issue with this is that I have elements which are null. The result of this query is as below.

{
    "pools": [
        {
            "_id": "311204638126768313",
            "name": "Gold Pool"
        },
        {
            "_id": "311205307447509280",
            "name": "Silver Pool"
        },
        null,
        null
    ]
}

So the question if the condition is false how do I not return anything or skip the iteration.

Map doesn’t have a way to skip an iteration. You can include/exclude items in/from a set or list by using Filter.

Yeap this works. Thanks.