types.Array.top
Method on every
arrayReturns the last element without removing it.
Return value
The last element.
Errors
Throws top() on a empty array when the array has no elements.
Notes
pop reads the same element and removes it.
Example
let a = [1, 2, 3];
println("a.top() =", a.top()); // peeks the last element
println("a.len() =", a.len()); // unchanged: top() does not remove anything
try { [].top() } catch (e) { println("[].top() throws:", e); }Output:
a.top() = 3
a.len() = 3
[].top() throws: top() on a empty arraySee also
pop | Removes and returns the last element. |
len | Returns the number of elements in the array. |
| array | class index |