Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda