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

258
Views
devolver [objeto HTMLDivElement] cuando se usa document.getElementById

Estoy insertando esto en mi div html:

 <script> document.getElementById("mArray").appendChild = '<%= mArray %>' console.log('<%= mArray %>') </script> <div id="mArray"></div>

luego, dentro de mi archivo js, tengo esto:

 var mArray = document.getElementById("mArray") console.log("33: " + mArray)

pero cuando lo registro me sale esto:

 33: [object HTMLDivElement]

quiero que devuelva los datos de la matriz, que deberían verse como [1,3,5,7,9]

¿Qué estoy haciendo mal?

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

0

Al leer, utilice

 var mArray = document.getElementById("mArray").textContent

y si desea usarlo como una matriz JS ( suponiendo que sea un formato de matriz js válido ), podría hacerlo

 var mArrayContents = document.getElementById("mArray").textContent; var myArray = JSON.parse( mArrayContents );

Además, al establecer el valor, no tiene que usar JS.
Puedes hacerlo directamente

 <div id="mArray"><%= mArray %></div>
about 4 years ago · Juan Pablo Isaza Report

0

En este momento, está registrando el elemento en sí, debe verificar los datos que contiene. Dependiendo de cómo se almacene la información, posiblemente podría obtener la información con algo como

 document.getElementById("mArray").innerHTML;

o

 document.getElementById("mArray").value;
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!