title: How to make plain array from nested?
body: <p>Here is an array:</p>
  <pre><code>let arr = [{key: 1, value: &quot;A&quot;, children: [{key: 2, value: &quot;B&quot;}]}]
  </code></pre>
  <p>I tried to make the plain list with the sequance number of elements:</p>
  <pre><code>let list = [{key: 1, value: &quot;A&quot;, &quot;num&quot;: 1}, {key: 2, value: &quot;B&quot;, &quot;num&quot;: &quot;1.1&quot;}]
  </code></pre>
  <p>My realization is:</p>
  <pre><code>  private productsWithNumber(products: any[]) {
      const arr = [];
      products.forEach((p, index: number) =&gt; {
        p['num'] = index + 1;
        if (p?.children) {
          p.children.forEach((element, index) =&gt; {
            element['num'] = `${p['num']}.${index + 1}.`;
            arr.push(element);
          });
        }
        arr.push(p);
      });
  
      return arr;
    }
  </code></pre>
  <p>As result I got wrong ordre of elements. How to simplify it?</p>