title: How do I find the last element in an array with JavaScript?
body: <p>I'm trying to return the last element in an array or, if the array is empty it should return null. What am I doing wrong / what is the best way to do this?</p>
  <p>Here's my code:</p>
  <pre><code>function lastElement(x, y, z) {
      if (lastElement.length &lt; 1 || lastElement === undefined) {
           return null; 
      }
      else {
          return(lastElement[lastElement.length - 1]);
      }
  }
  </code></pre>