I have 3 arrays whose elements are defined in a function. And later on, there is another file that needs to be able to read these. But I don't know how to allow the second file to see it.
Start.js
var array1 = [];
var array2 = [];
var array3 = [];
function doThings() {...} // The function will add things to the arrays
main.js
// Do things with the arrays
I've tried using require() but I get Uncaught ReferenceError: require is not defined
I've also tried using import() but I get Uncaught SyntaxError: Cannot use import statement outside a module
And when I try to add type='module'
to make <script type='module 'src="main.js" ></script>
I get:
from origin 'null' has been blocked by CORS policy
Can someone tell me what I'm doing wrong and how to fix it? Thanks in advance!