Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
Invalid writing of the forEach method

I have a question about foreach and subsequent capture of clicks.

When I use foreach like this, it works.

 let buttons = document.getElementsByClassName('button');
    
    for (let oneButton of buttons) {
        oneButton.addEventListener('click',function(){
            console.log('ahoj');
        })
    }

If I use it, but this is how it will write me a error: Uncaught TypeError: buttons.forEach is not a function

buttons.forEach(function(oneButton){
        oneButton.addEventListener('click',function(){
            console.log('Zdarec')
        })
    })

Can anyone explain to me why this tells me that forEach is not a function? It is clear to me that I can use the first option and move on, but I would like to know why the second option does not work.

I tried searching the internet, but I didn't find anything.

I will be happy for any answer.

Thanks :-)

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda