title: Iterating over array of objects with references to each other and resolve these from string to object
body: <p>I'm creating a preset system, where presets can "include" other presets.</p>
  
  <p>Preset A includes Preset B and C, while Preset B includes D and E.</p>
  
  <p>They all have this structure:
  - id
  - name (string, used as reference in include)
  - content (array of strings)
  - include (array of name, corresponding to the name prop)</p>
  
  <p>The content is what gets included.</p>
  
  <p>I tried coming up with a solution for the last 2 days, trying to wrap my head around recursion. I looked at the recursion related posts on here, but nothing really fits my scenario.</p>
  
  <pre><code>function getIncludes (original) {
      let output = [];
  
      function recursion (package) {
          if (package.content) output.push(package.content.join(' '));
          if (package.include) {
              return package.include.forEach(str =&gt; {
                  let c = presets.find(obj =&gt; obj.name === str);
                  if (c.content) output.push(c.content.join(' '));
                      recursion(c)
              });
          }
      }
  
      recursion(original);
      return output.join(' ');
  }
  </code></pre>
  
  <p>example presets obj</p>
  
  <pre><code>[
    {
      "id": 0,
      "name": "videoFormats",
      "content": ["(avi|mkv|mov|mp4|mpg|wmv)"],
      "hidden": true,
      "include": ["imageFormats"]
    },
    {
      "name": "audioFormats",
      "id": 1,
      "content": ["(ac3|flac|m4a|mp3|ogg|wav|wma)"],
      "hidden": true,
      "include": ["imageFormats"]
    },
    {
      "id": 2,
      "name": "imageFormats",
      "content": ["(bmp|gif|jpg|jpeg|png|psd|tif|tiff)"],
      "hidden": true
    },
    {
      "id": 3,
      "name": "media",
      "title": "Media",
      "include": ["videoFormats", "audioFormats"],
      "hidden": false
    }
  ]
  </code></pre>
  
  <p>I need a function that gives me a list of presets, the selected preset depends on.</p>
  
  <p>A function like this would work.</p>
  
  <pre><code>getIncludes("media") returning ["videoFormats", "audioFormats", "imageFormats"]
  </code></pre>