title: How to get last item in array Node.js?
body: <p>I am new to node.js and JavaScript so this question might be quite simple but I cannot figure it out. </p>
  
  <p>I have a lot of items in an array but only want to get the last item. I tried to use lodash but it somehow does not provide me with the last item in the array.</p>
  
  <p>My array looks like this now: </p>
  
  <pre><code>images : ['jpg.item_1', 'jpg.item_2', 'jpg.item_3', ..., 'jpg.item_n']
  </code></pre>
  
  <p>and i want to get: </p>
  
  <pre><code>images : 'jpg.item_n'
  </code></pre>
  
  <p>Using lodash I am getting: </p>
  
  <pre><code>images : ['g.item_1', 'g.item_2', 'g.item_n']
  </code></pre>
  
  <p>It looks like I am just getting the last letter in jpg, i.e. 'g'. </p>
  
  <p>My code using lodash looks like this: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const _ = require('lodash');
  
  return getEvents().then(rawEvents =&gt; {
  
    const eventsToBeInserted = rawEvents.map(event =&gt; {
      return {
  
        images: !!event.images ? event.images.map(image =&gt; _.last(image.url)) : []
  
      }
    })
  })</code></pre>
  </div>
  </div>
  </p>