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

193
Vistas
How to push to an array values from inside an arrow function

I'm trying to push to an array even numbers inside an arrow function but I don't how to push it in to that array.

My code:

var arrayEvenNumbers = [];
var evenNumbers = (arrayEvenNumbers) => {
  for (i = 2; i <= 20; i++) {
    if (i % 2 == 0) {
      arrayEvenNumbers.push(i);
    }
  }
}
console.log(evenNumbers(arrayEvenNumbers));

Really I'm a beginner and I've learned a bit, but I'm trying my best

Hope someone could help me to improve

Also I don't know if I'm sending the arguments properly And I'm not native english speaker so excuse if I can't express correctly :)

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

this way

var arrayEvenNumbers = [];

const evenNumbers = arr =>
  {
  for (let i = 2; i <= 20; i++)  
    if (i % 2 == 0)  arr.push(i);
 
  return arr
  }

console.log( evenNumbers(arrayEvenNumbers) )

console.log( arrayEvenNumbers )

about 4 years ago · Juan Pablo Isaza Denunciar

0

evenNumbers pushes it correctly, but returns undefined. You're probably looking to do:

evenNumbers(arrayEvenNumbers);
console.log(arrayEvenNumbers);
about 4 years ago · Juan Pablo Isaza Denunciar

0

this is the code you've forgotten the return statement:

var freeArr = [];
var evenNumbers = (arr)=>{
    for(i = 2; i <= 20; i++){
        if(i % 2 == 0){
            arr.push(i);
        };
    };
    return(arr);
};
console.log(evenNumbers(freeArr));

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