KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utilizing .slice() to View Large Collections in the Debugger
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: September 17, 2024

The 4D Debugger is a useful feature for investigating code behavior. The Debugger contains an expression pane, displaying the evaluated value on the right column. A limitation of the expression pane is that for both the multiple-element data structures: arrays and collections, the debugger will only display the first 100 elements.

A way to view additional elements with collections is to apply the .slice() function to the collection starting from the next 100 values to view. This will display the next 100 elements beginning from the passed parameter.

For example, if the collection $myCollection, has 450 elements, sticking $myCollection in the expression pane will display elements 0 to 99. The next 100 elements can be displayed by simply entering a second expression as $myCollection.slice(100). This will evaluate and display elements 100 to 199. The actual expresion should contain elements 100-450, but due to the limitation of the debugger only the first 100 values are displayed.

This can be continued to view the other 100 elements:
$myCollection.slice(200)
$myCollection.slice(300)
$myCollection.slice(400)
The last example will display the last 50 elements, using slice and passing an element past the limits will return an empty collection.
This can be helpful to quickly look through the elements of the collection being investigated without needing to modify the method.