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

255
Visualizações
Rewrite vanilla JS forEach into jQuery Each()

I am trying to keep my code consistent as I'm using jQuery for my project, however, I'm a bit confused about the each() method of jQuery.

let cells=$(".cell").toArray();

my Vanilla JS code is here:

cells.forEach(function(cell,index){
    cell.addEventListener('click',function(){
        console.log(cell,index);
    })
})

my jQuery is here:

cells.each(function(index,cell){
    cell.click(function(){
        console.log(cell,index);
    })
})

I know the code is wrong, as the console shows Uncaught TypeError: cells.each is not a function but I checked the jQuery Document, it says the each method is the forEach method in JS, I am really confused now.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

$(".cell").each is a function. $(".cell").ToArray().each is not a function.

jQuery's each method exists on a jQuery object, not on vanilla JS arrays.

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