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

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
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