title: How to get last item in map function in React
body: <p>I have an array of data that is returned to me from a CMS. I map over each item and return a component with the corresponding data. However, I need to target the last item in the <code>.map</code> function in the <code>render</code> method as the last item needs some modification.</p>
  <p>How would I do this?</p>
  <pre class="lang-js prettyprint-override"><code>return (
    &lt;div&gt;
      {data.body.map((item, i) =&gt; {
        console.log(i);
        if (item.type === 'button') {
          return &lt;ButtonComponent color=&quot;ffffff&quot; bgColor=&quot;4C319D&quot; text={item.text} textAlign=&quot;left&quot; id={item.id} /&gt;
        }
      })}
    &lt;/div&gt;
  )
  </code></pre>