Filter array of objects having array of objects

Q: How to filter an array of objects having an array of objects

Example object –


A  –  When we consider the above object having an array of superheroes in members. Each superhero having an array of power.

We need to get the superhero having the power 4/shield  in their power array, in this case

We apply the filter function on the members array, then we apply filter function on powers array present in every item in the members array in the following way.

Gives output

On applying the filter function on inner powers array, if we get the length of the resulting array greater than 0, it means that the inner array contains the power4/shiled .


No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *