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

251
Views
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 answers
Answer question

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 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!