dimanche 8 août 2021

Why am i receiving an empty array?

im trying to compare the individual numbers in the array that i am passing as one of the arguments of my function, to the other argument which is a single number. Id like to push the numbers that are not equivalent into a new empty array, then return that array but for some reason i am only receiving and empty array. it seems that the numbers are not getting pushed. Any help is greatly appreciated.


function removeChar(arr, num) {
  let newArray = [];
  for (number of arr) {
   
    if (!number === num) {
      newArray.push(number);
       console.log(newArray)
    }
  }
  console.log(newArray);
}


removeChar([2,5,4,3], 5)

Aucun commentaire:

Enregistrer un commentaire