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

335
Views
HTMLCollection obtiene todos los elementos del objeto

¿Cómo puedo hacer un bucle para que esta colección obtenga todos los elementos? He probado estos métodos pero no funcionaron.

 const collection = document.getElementsByClassName('fc-daygrid-day-top') the type is an object

El primer método

 for(let arr of Array(collection)){console.log(Array(collection)[i])} // Doesn't work

el segundo metodo

 var arr = [...collection]; // can't convert to array

¿Puedes saber cómo obtener todos los elementos de este objeto?

HTML

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

0

Aquí for(let arr of Array(collection)) matriz se crea con un solo elemento y es HTMLCollection y no se puede iterar. El constructor de matrices necesita elementos o tamaño. La HTMLCollection se coloca en una matriz como elemento único. Mejor use el operador de propagación para distribuir elementos en una matriz. for(let arr of Array(...elements))

Puede usar for let of ... para iterar a través de HTMLCollection.

 window.addEventListener('DOMContentLoaded', function(){ let elements = document.getElementsByClassName('test'); for(let element of elements) console.log(element.textContent); })
 <div class="test">1</div> <div class="test">2</div> <div class="test">3</div> <div class="test">4</div> <div class="test">5</div> <div class="test">6</div>

O conviértalo en una matriz con Array.from e itere

 window.addEventListener('DOMContentLoaded', function(){ let elements = document.getElementsByClassName('test'); Array.from(elements).map(element => console.log(element.textContent)) })

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!