Accessing Experiment Data Via Code Component for PsychoJS

Hi @Laur_R, for online tasks, you can access your response data using the following code. This example assumes you have a keyboard called key_resp and it has the correct answers defined in the keyboard component:

// Get JS array of trial objects (i.e., a list of python dicts with response data)
dat = psychoJS.experiment._trialsData

// Filter data to get correct trials
corr = dat.filter((trial) => trial['key_resp.corr'] === 1)

// Get RTs only as an array
rts = corr.map((trial) => trial['key_resp.rt'])

// Reduce RTs to a single number : the mean
meanRT = rts.reduce((a, b) => a + b) / rts.length