last
Returns the last element in an array.
- Check if
arris truthy and has alengthproperty. - Use
Array.prototype.length - 1to 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.