last
Returns the last element in an array.
- Check if
arr
is truthy and has alength
property. - Use
Array.prototype.length - 1
to compute the index of the last element of the given array and return it, otherwise returnundefined
.
Returns the last element in an array.
arr
is truthy and has a length
property.Array.prototype.length - 1
to compute the index of the last element of the given array and return it, otherwise return undefined
.