Dictionary keys() and values() in pavlovia / psychojs

Hi,
I am using the auto-translate on PsychoPy to generate the javascript of my custom python code. I am having a few problems with dictionaries. Can these be used with the auto translator or will I need to write the javascript manually?

Specfically I cannot use d.values() and d.keys(). The error message is TypeError: d.values is not a function

In the auto->js it doesn’t change the code- stays as d.values().
Thank you

@Adriel, if you can manually edit the JS code in the code component by setting code type to “Both”, the JS equivalent would be:

Object.keys(dict)
Object.values(dict)

Alternatively, you could write a Python loop to add the key, value pairs to separate lists, and this should translate without the need to manually edit the JS code.

1 Like