title: How to index an array with map method consisting of objects and arrays
body: <p>I have an array that is made from another array with the map method in JavaScript:</p>
  <pre><code>response = initialResponse.data.Resurs.map((item)=&gt;({
      KomRes:item.Kom,
      levels:
      [ 
      ...item.NumList.map((item)=&gt;(
        {
        KomRes:item.Number,
        })),
      ...item.SerList.map((item,index3)=&gt;({
        KomRes:&quot;Serial: &quot; + item.Ser,
        })),
    ]}));
  </code></pre>
  <p>So, I have an array of 1 object and one array of objects. Now, I want to add indexes so that the parent object and all of its child objects have different indexes. One example would be:</p>
  <pre><code>[
  {
   KomRes:&quot;abc&quot;
   id:1 // ==&gt; Here the id is different to the levels objects id-s
   levels:[{KomRes:&quot;cde&quot;,id:2},{KomRes:&quot;cdef&quot;,id:3}]
  },
  {
   KomRes:&quot;dfr&quot;
   id:4 // ==&gt; Here the id is different to the levels objects id-s
   levels:[{KomRes:&quot;dsf&quot;,id:5},{KomRes:&quot;sgsd&quot;,id:6}]
  },
  {
   KomRes:&quot;fgr&quot;
   id:7 // ==&gt; Here the id is different to the levels objects id-s
   levels:[{KomRes:&quot;zizu&quot;,id:8},{KomRes:&quot;hkl&quot;,id:9}]
  },
  ]
  </code></pre>
  <p>As you can see, all of the objects have different ids (indexes). How can I achieve that?</p>
  <p>I tried to add index to map method, but don't know how to achieve that with child map methods:</p>
  <pre><code>response = initialResponse.data.Resurs.map((item,index)=&gt;({
      KomRes:item.Kom,
      id:index,
      levels:
      [ 
      ...item.NumList.map((item)=&gt;(
        {
        KomRes:item.Number,
        })),
      ...item.SerList.map((item,index3)=&gt;({
        KomRes:&quot;Serial: &quot; + item.Ser,
        })),
    ]}));
  </code></pre>