Wakefield's Daily Tips

Custom function: remove

In Python list.remove(element) removes the first appearance of element from list, modifying list in place.

To mimic this behaviour in PsychoPy, add the following function in the Before Experiment of a JavaScript code component (or the JS side of a Both component).

Array.prototype.remove = function(value) {
    let index = this.indexOf(value); // Find the first occurrence
    if (index !== -1) {
        this.splice(index, 1); // Remove it in place
    }
};

Note, that this function isn’t the same as the one I’ve previously recommended but that function doesn’t seem to work any more. Perhaps it never did.