First, based on the title, I’d like to clarify that, at least in Harlowe 3.3, story-wide variables cannot be deleted. Temporary variables will be removed during a passage transition, but story-side variables remain until the story ends when the tab or window is closed.
For future searches, and those coming to this thread later, the key part of the example from the Cookbook is the following:
(for: each _item, ...$inventory)[\
_item (unless: $inventory's last is _item)[, ]\
].
In the above code, the (for:) macro performs an action on every entry in an array using the keyword “each”, the spread out operator, “…”, and a story-wide variable containing an existing array. This places each entry into a temporary variable, _item, which can be accessed inside of the associated hook. In the hook, the (unless:) macro is used to place a comma and a space, found within its own hook, after every entry in the array unless the value of _item is the same as the last entry in the array. If this becomes true, the comma and space are not used.
After each line, there is also a slash, “/”. This runs all the lines together, allowing the output to be on one resulting line, despite the code itself across multiple lines. This creates a comma separated listing of things in the array without an extra comma at the end of the list.
Removing from arrays (in Harlowe 3.3)
There are two ways to remove from an array.
The first follows the “only arrays can affect arrays” rule of Harlowe. To remove from an array, you need to create a new array with the value to remove. Then, the hyphen (subtraction) symbol can be used between the two arrays to remove entries with the same value(s) in both:
For example, to remove an entry with the value “A”, it would be the following:
(set: _exampleArray1 to (a: "A", "B", "C") )
(set: _newArray1 to _exampleArray1 - (a: "A") )
The second, and more complex answer, is to use a lambda to create a new array without the same value:
(set: _exampleArray1 to (a: "A", "B", "C") )
(set: _newArray1 to (find: _item where _item is not "A", ..._exampleArray1 ) )
In the second example, the (find:) macro is used to find all entries where some comparison is true, creating a new array in the process. In this case, find every entry where its value is not the value “A” across all entries, again using the spread out operator and a variable containing an existing array.
In either way, the string value “A” can also be replaced with a variable to more dynamically remove entries when needed.