Skip to content
Advertisement

Find empty arrays in nested array and remove them in Javascript

I have a nested and hierarchical array of objects, which looks like this

JavaScript

Now I want to remove the empty array "children": [] from the last children.

I’ve tried it with reduce but it doesn’t work without any error.

JavaScript

Advertisement

Answer

You could use recursion for that.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement