0

I've searched far and wide but can't seem to be able to find what I think is a sort of recursive alphabetize of an array withing arrays of objects in Javascript.

Almost every object in the array has an array which has multiple objects that also have multiple arrays.
I'm looking to just alphabetize each array by the object's name, but also look inside the objects to see if they have arrays that need to be alphabetized, and so on and so on.

Example data:

{
name: "Zero",
children: [
    {
    name: "Omega",
    children: [
        {
        name: "Harold",
        children: [{etc}]
        }
        ]
    }
    name:"Beta",
    children: [{etc}]
    }
]

I want to keep this same lay-out of the data while sorting each of the children alphabetically by name.
Example output:

{
name: "Zero",
children: [
          {
    name: "Beta",
    children: [{etc}]
    }
    name:"Omega",
    children: [
        {
        name: "Harold",
        children: [{etc}]
        }
        ]
    }
    }
]

Not just for the children of Zero but for every single children array there is inside each of the children, inside those and inside those.

  • @Terry And the _"Not just for the children of Zero but for every single children array there is inside each of the children, inside those and inside those"_ part? – Andreas Jun 05 '20 at 09:27
  • Yes, it's mostly the recursive part I'm having problems with. It seems like there's many ways to sort. But not enough ways to reach into arrays within arrays within etc. – Damnabillo Jun 05 '20 at 09:36
  • I've added two dupe targets for the recursive part – Andreas Jun 05 '20 at 10:06
  • Thank you very much! I never thought of using words like 'traverse' and 'iterate' in my searches. I'll try to see if I can make any of those work. – Damnabillo Jun 05 '20 at 10:18

0 Answers0