← Back to challenges

Return the Last Element in an Array

JavaScriptHardarraysvalidationlanguage_fundamentals

Instructions

Create a function that accepts an array and returns the last item in the array.

Examples

getLastItem([1, 2, 3]) ➞ 3

getLastItem(["cat", "dog", "duck"]) ➞ "duck"

getLastItem([true, false, true]) ➞ true

Notes

  • Don't forget to return the result.
  • If you get stuck on a challenge, find help in the Resources tab.
  • If you're really stuck, unlock solutions in the Solutions tab.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Century Crisis