KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: New .last() function in the Collection Class
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: July 27, 2023

As of 4D v20, the .last() function can be called on a Collection. The .last() function returns the last element of the collection.

Note:
This function does not modify the original collection. It returns Undefined if the collection is empty.

Example:

var $col; $emptyCol : Collection
var $last : Variant
$col:=New collection("hello"; 10; 20; 30; "world")
$last:=$col.last() // "world"

$emptyCol:=New collection() //empty
// $last:=$emptyCol[$emptyCol.length-1] //returns an error
$last:=$emptyCol.last() // returns Undefined