can I pass array object to javascript through script tag attribute from html?

I’m trying to pass an object (which ultimately I want to be an array but using string for now) like this:

<script> var myparameter="myvalue";
</script>

<script src="app.js"  data-par="michael" data-site=myparameter type="module"></script>

The other attribute (“michael”) does work, but I can’t pass the value of myparameter because it passes the string myparameter instead of the value of the variable.

Is there away to pass an object (or array) to the javascript script?

By the way, ultimately the values of the array would be too long to fit in one line as a tag attribute anyway, which is why I want to initialize it as a variable to be passed

Answer

In your app.js you will have access to the var myparameter. Because it is on the global scope.