Issue using a variable as an array value in code studio


I’m trying to create a ‘filters’ array for, however am running into difficulties as follows:

It works fine if I assign it some key:value pairs. For example:

1. let filters = [{"field_path":":PRO0000136GBJZS1","value":"1","comparator":"starts"}];

However, I want to use a variable. For example:
2. let filters = [myVariable];
The variable has exactly the same syntax as above, in other words: {“field_path”:“:PRO0000136GBJZS1”,“value”:“1”,“comparator”:“starts”}
But it does not work.

In Detective, the array returned by (1) is:

[0] => Array
[field_path] => :PRO0000136GBJZS1
[value] => 1
[comparator] => starts

The array returned by (2) is:

[0] => {“field_path”:“:PRO0000136GBJZS1”,“value”:“1”,“comparator”:“starts”}

Thanks for any help.


Resolved. ‘myVariable’ was a string so needed to be parsed with JSON.parse().