EDABIT:Return the Last Item in an Array

Return the Last Item in an Array

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

Examples

[1, 2, 3] ➞ 3

['cat', 'dog', 'duck'] ➞ 'duck'

[true, false, true] ➞ true

Notes

  • Don't forget to return the result.
  • All test cases contain valid data types.
  • If you get stuck on a challenge, find help in the Resources tab.
  • If you're really stuck, unlock solutions in the Solutions tab.
SOLUTION:
function getLastItem(arr) {
    var c = arr.pop();
    return c;
}

Comments

Popular posts from this blog

Basic CSS: Use Attribute Selectors to Style Elements

Basic CSS: Use Clockwise Notation to Specify the Padding of an Element

Basic CSS: Use Clockwise Notation to Specify the Margin of an Element