title: Recursive Map function
body: <p>I'm having hard time figuring out how to do this recursive map function.
  I have an array that look like this.</p>
  
  <pre><code>var array = [
        {
          id: 1,
          label: 'Satisfied customers',
          children: [
            {
              id: 2,
              label: 'Good food',
              icon: 'restaurant_menu',
              children: [
  
                { id: 3, label: 'Quality ingredients'},
                { id: 4, label: 'Good recipe' }
              ]
            },
            {
              id: 5,
              label: 'Good service',
              icon: 'room_service',
              children: [
                { id: 6, label: 'Prompt attention' },
                { id: 7, label: 'Professional waiter' }
              ]
            },
            {
              id: 8,
              label: 'Pleasant surroundings',
              icon: 'photo',
              children: [
                {
                  id: 9,
                  label: 'Happy atmosphere (not tickable)',
                  tickable: false,
                },
                {
                  id: 10,
                  label: 'Good table presentation (disabled node)',
                  disabled: true,
                },
                {
                  id: 11,
                  label: 'Pleasing decor',
                }
              ]
            },
            {
              id: 12,
              label: 'Extra information (has no tick)',
              noTick: true,
              icon: 'photo'
            },
            {
              id: 13,
              label: 'Forced tick strategy (to "strict" in this case)',
              tickStrategy: 'strict',
              icon: 'school',
              children: [
                {
                  id: 14,
                  label: 'Happy atmosphere',
                },
                {
                  id: 15,
                  label: 'Good table presentation',
                },
                {
                  id: 16,
                  label: 'Very pleasing decor',
                }
              ]
            }
          ]
        }
      ];
  </code></pre>
  
  <p>This is the array looks like...
  <a href="https://i.stack.imgur.com/FkAMm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/FkAMm.png" alt="enter image description here"></a></p>
  
  <p>As you can see the children is <code>recursive</code>.</p>
  
  <p>I need to put them into one array.
  My code doesn't work an has an error.</p>
  
  <pre><code>const result = [];   
  const map = (e) =&gt; {
  
      result.push({
          id: e.id,
          label: e.label,
      })
  
      e.children.map(map)
  
  
  };
  
  array.map(map);
  </code></pre>
  
  <p>the error is on <code>e.children.map(map)</code>.
  <a href="https://i.stack.imgur.com/MD4YV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MD4YV.png" alt="enter image description here"></a></p>
  
  <p>I need to push them all in array variable but I don't know how to do this. TY</p>