Closed mtrunt closed 3 years ago
Hi, take into account leavesOnly option is true by default, so this condition
if (key === 'badChildren') return false;
is never tested in your example.
Here is a demo for your case: https://codepen.io/yurigor/pen/WNGEJeN?editors=0010 let me know if this is what are you looking for.
Ah, that solves it! I was playing with the options but couldn't get it to work properly.
Thanks!
Currently using
filterDeep
you can remove objects based on some condition. However when an array meets those conditions, its children are still iterated even ifskipChildren
istrue
and the array ends in the resulting object if any of the children meets the condition.It would be useful to either have an option to avoid/stop this iteration or that
skipChildren
would also skip iterating arrays.Here's an example using the same objects as the docs with some added properties to show the use case.
The resulting object has the
badChildren
array with[{ name: 'bad child thing 1', good: true }, { name: 'bad child thing 2', good: true }]
since they matched thegood == true
condition.The expected object would have completely removed the
badChildren
array without even iterating its elements.Or is there a better way of accomplishing this?