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

150
Views
Using forEach to chain methods

One of the advantages I've heard for the use of forEach vs a for/of on an iterable is that you can chain methods together.

As a basic example of the two I have:

let arr = [1,2,3];
arr.forEach((elem, idx) => {
    console.log(elem);
})
for (let elem of arr) {
    console.log(elem);
};

What would be an example of chaining together multiple forEach's?

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

0

forEach returns undefined. You can't call a method on undefined.

The chaining you might have heard about is when forEach is at the end of some processing which returns an array, like after array methods like map,reduce etc:

let arr = [1,2,3];

arr.map(x => x*2).forEach((elem, idx) => {
    console.log(elem);
})

about 4 years ago · Juan Pablo Isaza Report

0

forEach always returns undefined. forEach is not chain-able like map, reduce or filter.

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!