Using .pop() online
The command lastItem = list.pop()
removes the last item from list and assigns it to variable lastItem.
Since 2023.2.3 and still present in 2025.1.0 there has been an issue with the Auto translation of .pop() such that it returns [lastItem] instead of lastItem (i.e. list is split into two lists – everything prior to the final item and a list just containing the final item.). The JavaScript code is lastItem = list.splice((list.length - 1), 1);
.
To compensate for this I now put online = False
on the Python side of a Begin Experiment code component tab set to Both, and online = true;
on the JavaScript side.
This allows me to do the following when using .pop().
if online:
lastItem = list.pop()[0]
else:
lastItem = list.pop()
which translates to:
if (online) {
lastItem = list.splice((list.length - 1), 1)[0];
} else {
lastItem = list.splice((list.length - 1), 1);
}
One advantage over this translation is that .pop(0) successfully removes the first item, which did not work before.
if online:
lastItem = list.pop(0)[0]
else:
lastItem = list.pop(0)