Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!