title: Filter array in array of objects in javascript
body: <p>I have an array of objects. Each object in array has also an array. I would like to filter both of arrays, parent one and nested one. For example I have an array like: </p>
  
  <pre><code>[{list:[1,2]},{list:[1,2,3]},{list:[1,2,3,4]}]
  </code></pre>
  
  <p>When I apply filter, which returns objects in which has list elements which has value greater than 2 and also nested list itself is filtered. It should return</p>
  
  <pre><code>[{list:[3]},{list:[3,4]}]
  </code></pre>
  
  <p>Obj1 is not returned, because list inside it does not have any values which are greater 2, for Obj2 only list:[3] is returned and for Obj3 only list:[3,4] is returned</p>
  
  <p>Is it possible to achieve without mutating original list?</p>
  
  <p>The following code filters objects which has elements which are greater than 2</p>
  
  <pre><code>parent
    .filter(obj =&gt; obj.list.some(el =&gt; el &gt; 2))
  </code></pre>
  
  <p>What should I do next?
  If I apply a filter for nested array like</p>
  
  <pre><code>...
    .filter(obj =&gt; obj.list.filter(el =&gt; el &gt; 2))
  </code></pre>
  
  <p>Then as a result I get <code>[[3],[3,4]]</code> but not object itself. Maybe anyone knows solution for that? </p>