Files
30-seconds-of-code/snippets/last.md
Angelos Chalaris bb722b2eb4 Updated examples
2017-12-27 16:35:25 +02:00

230 B

last

Returns the last element in an array.

Use arr.length - 1 to compute the index of the last element of the given array and returning it.

const last = arr => arr[arr.length - 1];
last([1,2,3]) // 3