mercredi 6 octobre 2021

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 :)

Aucun commentaire:

Enregistrer un commentaire