title: Using map() or similar function to return the array data in the following format
body: <p>I have the following javascript array (I'm having fun with map() today) - I want to be able to return the <code>pages</code> data but have the <code>page id</code> as the key and the index for the position of that page within the pages array as the value. What am I doing wrong?</p>
  <pre><code>let result = [
    {
        &quot;id&quot;: 10000089,
        &quot;units&quot;: [
            {
                &quot;id&quot;: 10000200,
                &quot;pages&quot;: [
                    {
                        &quot;id&quot;: 100000882
                    }
                ]
            },
            {
                &quot;id&quot;: 10000340,
                &quot;pages&quot;: [
                    {
                        &quot;id&quot;: 100000912
                    },
                    {
                        &quot;id&quot;: 100000915
                    },
                    {
                        &quot;id&quot;: 100000919
                    }
                ]
            }
        ],
    }
  ];
  </code></pre>
  <pre><code>// this is my attempt but doesn't return in the intended format below
  result.flatMap(el =&gt; el.units.map((e, i) =&gt; (e.pages)));
  </code></pre>
  <p>Expected output</p>
  <pre><code>pages = [
    100000882 =&gt; 0,
    100000912 =&gt; 0,
    100000915 =&gt; 1,
    100000919 =&gt; 2,
  ]
  </code></pre>
  <p>Here is a stackblitz to the code
  <a href="https://stackblitz.com/edit/js-mc9rqe" rel="nofollow noreferrer">https://stackblitz.com/edit/js-mc9rqe</a></p>