30秒学会 JavaScript 片段 – last
Returns the last element in an array.
Check if arr
is truthy and has a length
property, use arr.length - 1
to compute the index of the last element of the given array and return it, otherwise return undefined
.
继续阅读 30秒学会 JavaScript 片段 – last