set.last()

Learn: Sets

Get the last element of a Set.

Signature

last() => A | Null

Description

Returns the last element of the Set. The method reverses the Set and gets the first item.

Parameters

None

Return value

One of:

Type Description

Generic

Last element of the Set.

Null

Returned if the Set is empty.

Examples

// `toSet()` converts an Array to a Set.
let set = [1, 2].toSet()
set.last()
2
\