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

As of 4D v20, the .includes() function can be called on a Collection. The .includes() function returns True if the toSearch expression is found among collection elements, otherwise False.


Notes:
This function does not modify the original collection.
Pass the following toSearch expression to find in the collection:
      • Scalar value (text, number, boolean, date)
      • Null value
      • object or collection reference
Optionally, you can pass the index of collection from which to start the search in startFrom.


Example:

var $col : Collection
var $in : Boolean
var $obj : Object

$obj:=New object("value"; 100)
$col:=New collection(1; 2; "John"; 5; 3; "James"; 6; 4; "Alan"; 5; $obj)
$in:=$col.includes(3) //True
$in:=$col.includes(5; 6) //True
$in:=$col.includes("Ja@") //True
$in:=$col.includes("Hello") //False
$in:=$col.includes($obj) //True
$in:=$col.includes(New object("value"; 100)) //False