Bouncing values that escape

Tell us what’s happening:
Hi,

trying to work out the FALSE BOUNCER algorithm I came out with this behaviour that I cannot relate with anything I have seen. I think I understood that if you .push something in an array that you are traversing with a loop method it generates an infinite loop but why this returns the length of the array plus 1 while I was expecting to see the array plus 9 of *?

function bouncer(arr) {

  for (let i = 0; i<arr.length; i++){

    arr = arr.push('*');

  }

      console.log(arr);

}

bouncer([1,2,3,4,5,6,8,9,456]);

I tried to understand but in vain
L

Your code so far


function bouncer(arr) {
for (let i = 0; i<arr.length; i++){
  arr = arr.push('*');
}
    console.log(arr);
}

bouncer([1,2,3,4,5,6,8,9,456]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.

Challenge: Falsy Bouncer

Link to the challenge:

I think the problem is asking to return array which don’t contain any false value like mentioned in problem( false , null , 0 , "" , undefined , and NaN .) . In this problem we have identified these value and not to insert in another array . Here is my solution . we iterate all values of array if it is not falsy then it enter into if and pushed into new array .
function bouncer(arr) {
var arr1 =;
for (let i =0 ;i<arr.length ;i++)
if(arr[i]){
arr1.push(arr[i]);
}
return arr1;
}

This doesn’t have anything to do with the challenge, but:

Push pushes a value into the array and returns the new length of the array.

arr is [1,2,3,4,5,6,8,9,456].
Loop runs first time, arr is set to the number 10, i to 1
arr is 10
For some reason, there isn’t an error (10 doesn’t have a length, so I’d expect this to happen, but it doesn’t). Anyway, loop ends, log 10.

The reason that you receive the length of the array is because the push method ‘adds one or more elements to the end of an array and returns the new length of the array.’ Please read the first section of the article below which explains the method in detail and has a useful example too : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push

Hi,
thank you for the indication…I should have remembered that *the push method … and returns the new length of the array.’ *
Cheers
L