How to replace a html entity within script tags using Craft replace Apologies if this has been asked before, I can only find questions dealing with the reverse scenario (i.e. replacing special characters with html entities)

I need to output special characters as part of a JavaScript array using Craft. Currently the values are output with all special characters replaced by their html equivalent. (e.g.: ampersands are replaced by &amp;amp )

I have tried restoring the special characters using craft replace but without success.

The following code works to replace text, but does not, for example, replace &amp;amp with &amp;, or rather perhaps it does not distinguish these values as distinct.

&lt;script&gt;

    var myVariable = [{% for value in myArray %}"{{ value|replace('raw-html-entity', 'special-character') }}"{%- if not loop.last -%},{% endif %}{% endfor %}];

&lt;/script&gt;


This code is being used for an array which is used for jQuery autocomplete values, so raw html is not appropriate.

Any suggestions appreciated.
I have a Craft Helpers plugin on GitHub, which has a htmlEntityDecode Twig filter.

{{ value|htmlEntityDecode}}